Why is WSGIScriptAlias not having an effect? - apache

I'm running into an issue with setting a WSGIScriptAlias in Apache, where attempting to use the alias is giving a 404 error due to trying to reach the "literal" URL. Here's the test set-up in my Apache2 sites-available/000-default.conf (mimicking the mod_wsgi Quick Start Guide):
DocumentRoot /var/www/html
WSGIScriptAlias /wsgi_test /var/www/html/test.wsgi
<Directory /var/www/html>
Order allow,deny
Allow from all
</Directory>
After restarting Apache2 and going to mydomain.com/wsgi_test, a 404 page is displayed. The first line of Apache's error.log file below shows the server attempting to access the URL path wsgi_test in DocumentRoot, not the aliased file path:
AH00128: File does not exist: /var/www/html/wsgi_test
AH01964: Connection to child 1 established (server nathanclonts.com:443)
(70007)The timeout specified has expired: [client 67.161.148.188:33883] AH01991: SSL input filter read failed.
The file /var/www/html/test.wsgi has the same code as the above-mentioned Quick Start Guide:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
With permissions set to:
-rwxrw-r-- 1 username www-data 278 Apr 16 11:31 test.wsgi
Does anyone have suggestions on where to look for other configuration that may be affecting this, or any other debugging tips?
What's odd is that I have set up another (Django) application with mod_wsgi that is currently working in the same VirtualHost, but obviously I'm missing something in this test.

This was resolved by updating the <VirtualHost *:443> configuration file to include the WSGIScriptAlias line (as the server uses SSL), instead of having WSGIScriptAlias under the <VirtualHost *> configuration.
I wasn't aware that all Aliases needed to be included in the 443 port to function, but eventually worked it out after playing with a vanilla Alias and locating which files they were defined in with:
grep -R "Alias" /etc/apache2/*

Related

403 error forbidden you don't have permission to access /myapp on this server mod_wsgi and apache

I have installed mod_wsgi as an Apache module and I want to run a simple hello world application to see that the module works properly.
I have followed this guide, which is based on the official Quick Configuration Guide.
After completing all the steps I get a 403 error
Forbidden You don't have permission to access /myapp on this server..
I am using Apache/2.4.10 on Raspbian and my installed mod_wsgi version is
libapache2-mod-wsgi-py3 4.3.0-1 armhf Python 3 WSGI adapter module for Apache.
I have added example.com to my hosts' file as follows:
127.0.0.1 localhost example.com
I created the example.com.conf file in /etc/apache2/sites-enabled/ with contents:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin test#test.com
DocumentRoot /usr/local/www/documents
<Directory /usr/local/www/documents>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
myapp.wsgi contents:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!\n'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
and created the files/folders for the hello world application with the following permissions:
drwxr-sr-x 2 root www-data 4096 Feb 1 13:18 documents
drwxr-sr-x 2 root www-data 4096 Feb 1 13:22 wsgi-scripts
I also made sure that example.com is served locally and not through DNS with ping.
I cannot understand why my installation is not working.
Are any further configuration options missing or is there something wrong with any of my settings?
I figured it out after a few modifications.
The new example.com.conf file is:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /usr/local/www/documents
<Directory /usr/local/www/documents>
Require all granted
Satisfy Any
</Directory>
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
<Files myapp.wsgi>
Require all granted
Satisfy Any
</Files>
</Directory>
After the syntax changed to match apache 2.4 I got 500 Internal Server Error, which upon further investigation inside apache error.log file indicated the following error:
[wsgi:error] [pid 11216] [client 127.0.0.1:56642] mod_wsgi (pid=11216): Exception occurred processing WSGI script '/usr/local/www/wsgi-scripts/myapp.wsgi'.
[wsgi:error] [pid 11216] [client 127.0.0.1:56642] TypeError: sequence of byte string values expected, value of type str found
To solve this error I changed the output variable assignment in myapp.wsgi file from output = 'Hello World!\n'
to output = b'Hello World!' as it is indicated here.

How to suexec public_html/cgi-bin without the "~user/" in url

Apache 2.4.29 (Fedora)
Perl v5.26.1
I have a website which is run, for several reasons, out of the public_html directory of the user "jaf". Apache is set up to run cgi scripts in this directory tree as the local user ("jaf"). So, for instance "http://billyard.ca/~jaf/cgi-bin/simpletest.cgi" successfully executes as user "jaf" (rather than the default "apache"). What I am trying to achieve, unsuccessfully so far, is the following:
To get apache to run all cgi called by "http://billyard.ca/cgi-bin/" as if they were called by "http://billyard.ca/~jaf/cgi-bin/" (i.e., omit the "~jaf/") yet still operate within the "~jaf/public_html" directory as user "jaf" rather than "apache". I've added the following to the apache configuration:
<VirtualHost *:80>
Servername billyard.ca
SuexecUserGroup jaf jaf
DocumentRoot "/home/jaf/public_html"
ScriptAlias /cgi-bin/ /home/jaf/public_html/cgi-bin/
</VirtualHost>
This works "billyard.ca/~jaf/cgi-bin/simpletest.cgi".
This fails "billyard.ca/cgi-bin/simpletest.cgi"; it gives me a 500 internal server error and suexec reports "command not in docroot".
To get selinux to allow this (right now I have to go into permissive mode otherwise I get apache "premature end of header" error messages)

unable to setup wsgi with httpd for running python based web app

I have archlinux.
I installed httpd and mod_wsgi
and added the following in the /etc/httpd/conf/httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
after this how to put the things in the virtualhost file.
Still i tried:
<VirtualHost *:80>
ServerName localhost
WSGIScriptAlias / /home/simha/.public_html/public_wsgi/wsgi-scripts
<Directory "/home/simha/.public_html/public_wsgi/wsgi-scripts">
Options All Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have put a testing script called wsgi_app.py in the /home/simha/.public_html/public_wsgi/wsgi-scripts folder.
the wsgi_app.py script is
#-*- coding: utf-8 -*-
def wsgi_app(environ, start_response):
import sys
output = sys.version.encode('utf8')
status = '200 OK'
headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, headers)
yield output
# mod_wsgi need the *application* variable to serve our small app
application = wsgi_app
(Also i dont understand what is this code doing). i got it from archlinux.
when go to localhost in the browser, i get
Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Any help.
This error is generally caused by the fact that your home directory has permissions such that other users cannot access anything in it. This will cause a problem as Apache httpd will run as a distinct user.
Move your application to a directory outside of your home directory, such as under /var/www.

Apache virtual host issue

I am trying to get Symfony to work without using the built in PHP server, however, I always get 403 when trying to access it via my virtual host address. My virtual host conf file looks like this:
<VirtualHost *:80>
ServerName www.symfony2.local
ServerAlias symfony2.local
DocumentRoot /var/www/vhosts/symfony2.local/web
<Directory /var/www/vhosts/symfony2.local/web>
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/symfony2-error.log
CustomLog /var/log/httpd/symfony2-access.log combined
</VirtualHost>
My hosts file looks like this:
127.0.0.1 symfony2.local
The .htaccess in web/ is the default Synfony2 installed file.
Whenever I try to access http://synfony2.local I get the following error in my log file:
(13)Permission denied: [client 127.0.0.1:32858] AH00529: /var/www/vhosts/symfony2.local/web/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/var/www/vhosts/symfony2.local/web/' is executable
-rwxr-xr-x. 1 apache apache 2.8K Mar 1 00:48 .htaccess
drwxr-xr-x. 3 apache apache 4.0K Mar 1 01:24 web
Can someone please point out what I am missing here?
There could be serveral reasons for the 403 foribben.
Reduce the permissions on the .htaccess file. You have the wrong
permissions on the htaccess file. You have it as 755 which should be used on directories and it should
be 644 rw-r--r--. Change it. My guess is that's the problem.
Make sure you have an index file in the web root. Of course if you have a web app there then make sure you have the DirectoryIndex index.php specified in the Apache config file.
Make sure the parent folder is 755 symfony2.local also which has been known to restrict access.
Option 2 and 3 are something to check if 1 doesn't fix it. Although you need to change the perms on htaccess regardless.
The solution by Panama Jack was useful and the points raised valid, however, it did not resolve the issue (although it may have had an effect).
I finally managed to get it to work after disabling SeLinux.

Forbidden error in apache virtual host setup

Hello I have been looking through internet articles forums to solve my issue and so far it has been to no avail. I am trying to set up an Apache virtual host for my FuelPHP development on localhost but I keep getting slammed with the error 403 message. Here is my current setup.
#/etc/apache2/sites-enabled/000-default
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot "/home/supercomputer/Desktop/PHP/fuelProject/public"
ServerName localhost.home
<Directory "/home/supercomputer/Desktop/PHP/fuelProject/public" >
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
I have pointed my Docroot to the public folder inside my fuelProject. Also to make sure Apache had access to the server files, I set the permissions for all of the files recursively to read, write, and execute just to be a 100% safe. Any clues as to what else could be going wrong?
PS: I am running ubuntu raring (13.04)
PSS: And I am trying to visit localhost.home and localhost.home/index.php. I also get the following warnings upon restarting the server
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:59 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
Here is the correct way of adding Vhost for fuelphp application or any other php application
<VirtualHost *:80>
ServerName localhost.home
DocumentRoot /home/supercomputer/Desktop/PHP/fuelProject/public
ServerAdmin webmaster#localhost
<Directory /home/supercomputer/Desktop/PHP/fuelProject/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And also the below line is not required I dont know why you have added
NameVirtualHost *:80
After doing all above add a host entry to your machine to do that
sudo vi /etc/hosts
add an entry of the virtual host
127.0.0.1 localhost.home
After doing all these things
restart Apache by running
sudo /etc/init.d/apache2 restart
And just load http://localhost.home in your browser you should be able to see your site up and running .
If you still get forbidden error .you need to give permissions to your whole application folder
follow run these commands to do so
sudo chown -R www-data:www-data /home/supercomputer/Desktop/PHP
sudo chmod -R 775 /home/supercomputer/Desktop/PHP
At last add yourself to www-data group
sudo adduser yourUserName www-data
The configuration I posted were working. The problem was with permissions. I had set only my containing fuel project folder to permission 777 but for some reason apache wanted access to almost all the folders containing it. Weird I know but setting all the permissions to 777, it worked. Reading the darn apache log sure helped. If you are having a similar problem, I suggest find the apache log and ACTUALLY READ IT
Testeed on Ubuntu 14.04: I did everything above but I didn't work. I missed to allow access to the directory in my apache2.conf. This is needed if you don't use a standard directory like /var/www or /usr/share/.
<Directory /usr/local/vufind>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This was mentioned on the4 default PHP site. It's worth reading it!