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

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.

Related

403 error with LAMP and symfony

With a LAMP server running on Ubuntu 16.04, I get the error in the log file defined as in conf :
[Tue Dec 26 16:56:35.930629 2017] [core:error] [pid 21749] (13)Permission denied: [client 127.0.0.1:43872] AH00035: access to / denied (filesystem path '/home/christophe/public_html') because search permissions are missing on a component of the path
I set my .conf file with the following :
<VirtualHost *:80>
ServerName memory.test
ServerAlias www.memory.test
DocumentRoot /home/christophe/public_html/memory/web
<Directory /home/christophe/public_html/memory/web>
AllowOverride All
Require all granted
Allow from all
</Directory>
ErrorLog /var/log/apache2/memory_error.log
CustomLog /var/log/apache2/memory_access.log combined
</VirtualHost>
The access right are set for user christophe:christophe and www-data is part of the group christophe, the mod is 775 but even with the www-data:www-data I get the error.
The /etc/hosts file contains the line :
127.0.0.1 memory.test
I seem to not have selinux installed as this solution is given in some other questions. I would not consider myself as a newbee and I succeeded to have many test environments working this way but this linux is a fresh installation and for a while no other website is working on it...
Did you check that you have 0644 in the directory you are trying to serve?, besides, you also give permissions to www-data user to access that directory, note that the folder you are trying to serve is located in your home directory.

Why is WSGIScriptAlias not having an effect?

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/*

apache 2.4 on fresh fedora: AH01630: client denied by server configuration

I've seen hudreds of questions like this and most of them end up in changing the syntax to latest Apache version or messing up with .htaccess. But not in my case since I used fresh F23 install and never played with erarlier Apache versions. I'm trying to set up a simple virtual host that binds to one of my IP's. Here is what I put in /etc/httpd/conf.d/internal.conf
Listen 10.10.1.177:80
<VirtualHost 10.10.1.177:80>
DocumentRoot "/home/www"
DirectoryIndex index.html
ServerName internal:80
<Directory “/home/www“>
Options All Indexes FollowSymLinks
Options +Indexes
Require all granted
</Directory>
LogLevel debug
ErrorLogFormat "%{cu}t %M"
ErrorLog /var/log/httpd/internal-error.log
CustomLog /var/log/httpd/internal-access.log combined
</VirtualHost>
When I try:
curl http://10.10.1.17
From other host in that network, first 403 page appears and get redirected to default fedora-apache page. This entries entries gets into error log:
2016-04-21 22:45:50.610696 AH01626: authorization result of Require all denied: denied
2016-04-21 22:45:50.610724 AH01626: authorization result of <RequireAny>: denied
2016-04-21 22:45:50.610729 AH01630: client denied by server configuration: /home/www/
2016-04-21 22:45:50.610763 AH01626: authorization result of Require all granted: granted
2016-04-21 22:45:50.610771 AH01626: authorization result of <RequireAny>: granted
I just want this virtual server to serve anything that I put to /home/www. What am I missing?
I changed main httpd.conf file to bind to my other network interface.
I have "greped" all .conf files for "deny|denied" statements and found only default "Require all denied" for "/" directory and .ht files in main config.
There is a LocationMatch directive in /etc/httpd/conf.d/welcome.conf that is causing this behavior:
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
Comment out the comments of that file (or empty out that file), but
do not remove that file, because a subsequent upgrade of the httpd
package will then bring it back. It will not be overwritten if you
have modified it locally.

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!

Virtual host showing apache test page and everything else in doc root is forbidden

I am using a new CentOS 6.3 minimal install with fresh httpd installed
When I go to my virtual host it is showing me the apache test page, and then if I go to mydomain.co.uk/index.html (That I have just set up to test with) it says forbidden. All the usual answers to this don't seem to be working and I have honestly looked through tons of forums and other people questions/answers and nothing seems to be working for me.
I have created a group called 'www' that I have added the user 'apache' to.. This is my root directory in httpd.conf file, I have left it pretty open just for testing:
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
This is my vhosts file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/
</VirtualHost>
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias www.domain.co.uk
DocumentRoot /home/domain/public_html
<Directory "/home/domain/public_html">
Options Indexes FollowSymLinks ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
From /home/ onwards I have set the group to www
When ls -lA on home folder I get
drwxrwsr-x. 5 root www 4096 Feb 5 20:57 home
The error I am getting in my logs file is a permission one:
[Wed Feb 06 10:24:42 2013] [error] [client 62.254.7.226] (13)Permission denied: access to /index.html denied (filesystem path '/home/domain/public_html/index.html') because search permissions are missing on a component of the path
As is everything else in that folder. I really don't know what to try next. I have come to the point of needing to ask for my specific setup as following other tutorials or answers has not worked for me. Any help is greatly appreciated!
Error 13 means that the user/group specified in your apache configuration (httpd.conf) didn't have permission to access the files. The files, and all the directories above them, need to have permission that allow for that user and group.
One of the trickier bits can be extended permissions. If you are running selinux, the server user could be denied because of the extended permissions on the file. To check for this, run (from the command line):
setenforce 0
If the problem goes away (i.e. the page is visible) then your extended permissions are blocking access.
See http://wiki.apache.org/httpd/13PermissionDenied for details.
Selinux is not expecting the http server to access files under /home/domain since it is not a standard path.
You can change it with following command:
chcon -R --type=httpd_sys_rw_content_t /home/domain/public_html/