Apache2 cannot run WSGI script - apache2

I'm installing Reviewboard on linux, I have copied the config provided by the install package to httpd.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/usr/www/reviewboard/htdocs"
# Error handlers
ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
WSGIScriptAlias "/reviewboard" "/usr/www/reviewboard/htdocs/reviewboard.wsgi/reviewboard"
<Directory "/usr/www/reviewboard/htdocs">
AllowOverride All
Options -Indexes FollowSymLinks
Allow from all
</Directory>
# Alias static media requests to filesystem
Alias /reviewboard/media "/usr/www/reviewboard/htdocs/media"
Alias /reviewboard/errordocs "/usr/www/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/usr/www/reviewboard/htdocs/media/rbcommons/images/favicon.png"
</VirtualHost>
However, when I access "http://SITE/reviewboard/htdocs/reviewboard.wsgi", it just gives me the file in plain text instead of running the script
I have checked the mod_wsgi is running on apache2 by "apache2ctl -t -D DUMP_MODULES"
Did I miss any other configuration?

You should be using the URL:
http://SITE/reviewboard
and the WSGIScriptAlias directive should be:
WSGIScriptAlias "/reviewboard" "/usr/www/reviewboard/htdocs/reviewboard.wsgi"
Do be aware though that it is bad practice to be putting your whole Django site under DocumentRoot. That you are seeing the source code for the WSGI script file highlights why it is bad. That is, have an issue with your Apache configuration and you could expose all your source code for people to download. Especially bad if settings.py is in there and it contains database passwords.
Now, address those issues and update question with what you then have and what next problem is as I don't expect that to completely solve the problem because with those mistakes you should have got a different problem than what you describe, so suspect that your configuration is not even being used.

Related

403 Forbidden after changing DocumentRoot

So, I've tried running a domain, a sub domain and another domain on one machine. I've set up a conf file for every site:
<VirtualHost *:80>
ServerName websitea.com
ServerAlias www.websitea.com
DocumentRoot /var/www/html/weba
</VirtualHost>
<Directory /var/www/html/weba>
Order allow,deny
Allow from all
Require all granted
</Directory>
The same folder config can be found in apache2.conf as well (I tried experimenting with it) and it's the same config across all sites.
The issue is that after putting this DocumentRoot and disabling 000-default.conf I get 403 forbidden.
What I've tried doing so far:
Changing owner to www-data:www-data
Changing perms to 755/777
Putting the directory configurations in
apache2.conf or the website's conf putting all sites in 1 file
all kinds of directory settings (Options Indexes FollowSymLinks,
AllowOverride none/all, Require all granted, Allow from all, Order
Allow,Deny)
but none would work...
EDIT: I found out that the website goes to /www/var/html/ even though the domain is set to get to /www/var/html/weba, DocumentRoot pretty much does nothing in the configurations.
It seems you created a new virtual host configuration file on this path /etc/apache2/sites-available/
you need to enable the website virtual host conf file, for example, id website virtual host conf file name is 'websitea.conf'
then you need run below command
sudo a2ensite websitea.conf

404 not found image using Alias in apache2

I have set up a really basic site using the default apache2 config settings, and I can't get an alias directory set up properly.
I've tried following a number of guides and stackexchange posts on setting this up, but there must be something I'm still missing. I've gone through a number of versions of this and tried to simplify as much as possible.
Here's my apache2 default site config
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /js/ "/usr/share/apache2/js/"
<Directory "/usr/share/apache2/js/">
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The alias from the default configuration in mods-available/alias.conf, Alias /icons/ "/usr/share/apache2/icons" works fine. I can access siteurl.com/icons/a.gif, but siteurl.com/js/a.gif is giving me a 404 error, despite there being a copy of a.gif in that folder.
I've done service apache2 restart. I've tried a2enmod/a2ensite to re-add the config files, but it says they are already loaded. This seems really simple, so I'm not sure what I'm missing here. Thanks.
After restarting the server and clearing the browser cache it is working properly.

Vagrant 403 Forbidden

I've been running Vagrant successfully for about a week. Last night I ran vagrant reload and now I can no longer access my sites.
VirtualBox version 4.2.16
Vagrant version 1.2.7
My Vagrantfile and bootstrap.sh: https://github.com/kriskd/vagrant-settings
Running on Mac
My files live at /vagrant/Sites. At first my "welcome page" which lives at /vagrant/Sites rendered at
http://localhost:4567/
All my projects are folders under Sites. For example, /vagrant/Sites/test won't render index.html. I get the following
Forbidden
You don't have permission to access / on this server.
Apache/2.4.6 (Ubuntu) Server at localhost Port 4567
The vhost looks like:
<VirtualHost *:80>
DocumentRoot "/vagrant/Sites/test"
ServerName test
<Directory "/vagrant/Sites/test">
AllowOverride All
</Directory>
</VirtualHost>
The vhosts are owned by root. My project files are owned by vagrant and chmod'ed 0777.
After no success, I did a full vagrant destroy followed by vagrant up and then the localhost host welcome page stopped rendering as well with the forbidden error.
My hunch is that this is not a vagrant issue at all but solely an Apache configuration glitch. There are a few things I can think to check.
First, obviously, is to confirm that the user that apache is running under has read and execute permissions for the DocumentRoot folder.
Since you mentioned Apache 2.4, there have been changes in the configs from 2.2. Make sure your Allow from all statements now read Require all granted. (If you were still on 2.2, you'd want to make sure they said Allow from all instead of Deny from all.) In either case, you can set this in each <VirtualHost> individually, or set a default in your <Directory /> block of the main httpd.conf file.
Getting more obscure, you could check for selinux, although I'm pretty sure this isn't present in Ubuntu by default. (It is in CentOS, for example.)
This is solved and in the end came down to some very simple things.
Use "Require All granted" instead of "Allow from All"
Put each websites' content at the same level namely /vagrant/Sites/default, /vagrant/Sites/test, /vagrant/Sites/real-site
Add .conf extension to vhost names such as test.conf and real-site.conf
Add AllowOverride All to vhosts to respect sites' .htaccess file (I realize that was in my original post, it got lost as I tried to solve this)
All very basic things that eluded me for a better part of a week. I hope this can help someone else.
I had the same problem when changing the DocumentRoot.
Since you've changed your DocumentRoot to "/any/path/foo/bar", make sure you have the permissions set on "apache2.conf" for this path.
Search for:
<Directory /any/path/foo/bar>
in apache2.conf
And add a new block like this:
<Directory /any/path/foo/bar>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And my guess is that everything is gonna be fine!
cd /etc/apache2/sites-available
for file in `ls *`; do sed 's/\(.*<\/Directory.*>\)/Require\ all\ granted\n\1/' $file > $file.new;mv $file.new $file ; done;
because it worked before, I would not waste time on fix file by file

How to fix ERROR: Site domain.com does not exist, while adding subdomain to apache2?

I'm trying to add subdomains to my home server.
svn.domain.com
trac.domain.com
Due to dynamic IP I use dyndns service, on top of that I have domain.com hosted somewhere else. I created CNAME for subdomains on remote host to point to my user.dyndns.org domain.
So now when I visit either of subdomains: trac or svn, I see "It works!" message.
This done, I created two virtual host files under /etc/apache2/sites-enabled
file1: svn.domain.com and file2: trac.domain.com
contents:
<VirtualHost *:80>
ServerName trac.domain.com
DocumentRoot = /var/www/trac/repos
<Directory /var/www/trac/repos>
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And
<VirtualHost *:80>
ServerName svn.domain.com
DocumentRoot = /var/svn/repos
<Directory /var/svn/repos>
Order allow,deny
allow from all
</Directory>
</VirtualHost>
But I get error: ERROR: Site trac.domain.com does not exist!
what am I doing wrong?
I had this problem when upgrading from Apache 2.2 to Apache 2.4. The (ridiculous) solution was to ensure all files end with .conf, or a2ensite would ERROR: Site example does not exist!.
Also, when linked manually in sites-enabled, they would not even load without the .conf extension.
I also came across the same problem when I upgraded from Apache 2.2 to 2.4; all my virtual hosts suddenly broke and while trying to search for why this was the case, I stumbled across this question.
It turns out the reason is because of a difference between my old apache2.conf and the new apache2.conf. My old Apache 2.2 conf file had the line
Include sites-enabled/
whereas my new Apache 2.4 conf file had the line
IncludeOptional sites-enabled/*.conf
Lo and behold, when I changed the line to
IncludeOptional sites-enabled/
everything went back to normal.
Try moving the files to /sites-available. Then run a2ensite svn.domain.com and a2ensite trac.domain.com and reload Apache.
if you type a2ensite. it will prompt. Which sites do you want to enable (ie., after you put a .conf file in the sites-available and link it from sites-enabled.
a2ensite expect the full name of the conf file with the .conf extension
a2ensite ONLY accepts .conf files, so copy all sites in sites-available so the have a .conf extension (renaming didn't work itconfused the linkssomehow), erase the original files from sites-available AND sites-enabled. use a2ensite on the new files (you don't need to add .conf) and it all works, with our without the *.conf in /etc/apache2/apach2.conf
There must be some "memory" of the original file even when it is renamed -the symbolic link renames also, butthe erases & enabling "new" .con files works and you can then use a2dissite and a2ensite as before
1) remove all default site inside sites-enable
a2dissite <site-configuration-file-name>
2) take a closed look at your config file: start with a minimum properties like:
<VirtualHost [Domain]:80>
ServerAdmin webmaster#localhost
ServerName [Domain]
DocumentRoot [webAppPath]
<Directory [webAppPath]>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/my_domain_name_error.log
CustomLog ${APACHE_LOG_DIR}/my_domain_name_access.log combined
</VirtualHost>
My solution for local server name is replacing:
sudo a2ensite serverName
with
sudo a2ensite serverName.conf

Apache virtualhosts and default server not working as expected (serving incorrect content)

I've been playing around with this for a couple of hours and have come to the conclusion that asking someone is probably the best way forwards!
I have a fairly out-of-the-box apache install (I've added mod_security and mod_python) so not touched /etc/httpd/conf/httpd.conf
I have a number of domains all running as 's and each with its own individual config file. They are all working as expected except for the fact that any unrecognised hostname will serve the content from the first virtualhost (which I know is the expected behaviour as the content from the first virtualhost is served)
I would like to set up a default set of content to be served if someone reaches my server through an unknown hostname - but in doing so, the first site now also serves this default content which I can't seem to find a reason for.
All of the config files for the individual sites are located in /etc/httpd/conf.d/sites (so that the are not auto-included) and are then included through a file (/etc/httpd/conf.d/sites.conf) which I created - before trying to set up the default server, its content is this:
Include conf.d/sites/*.conf
I modified it to be this to try to get the default server working:
<VirtualHost _default_:80>
DocumentRoot /home/sites/DEFAULT
<Directory "/home/sites/DEFAULT">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Include conf.d/sites/*.conf
Just to re-iterate the problem - when the second version of sites.conf is active, the first VirtualHost also serves this content; the rest are fine. All of the sites' config files are syntactically correct and have no typos in the ServerNames.
(For reference, I have included the config file for the offending site - stored in /etc/httpd/conf.d/sites/DOMAIN.clintonmontague.co.uk.conf)
<VirtualHost *:80>
DocumentRoot /home/sites/clintonmontague.co.uk/www
ServerName clintonmontague.co.uk
LogLevel emerg
CustomLog /home/sites/clintonmontague.co.uk/_logs/access_log "combined"
<Directory "/home/sites/clintonmontague.co.uk/www">
AllowOverride none
allow from all
Options +Indexes
</Directory>
</VirtualHost>
Sorry for the overly-long question!
Other info: Apache 2.2, CentOS 5, MediaTemple (dv)
If what you say in your answer is correct, then try this. Note the ServerAlias line which should work instead of the PHP code:
<VirtualHost *:80>
DocumentRoot /home/sites/clintonmontague.co.uk/www
ServerName clintonmontague.co.uk
ServerAlias www.clintonmontague.co.uk
LogLevel emerg
CustomLog /home/sites/clintonmontague.co.uk/_logs/access_log "combined"
<Directory "/home/sites/clintonmontague.co.uk/www">
AllowOverride none
allow from all
Options +Indexes
</Directory>
</VirtualHost>
Just for reference - it appears that the problem was because /etc/sysconfig/network reported my HOSTNAME as clintonmontague.co.uk (which happened to be the first domain alphabetically). Therefor, default included that domain name so the default content was being served.
Thought I'd post the answer in case anyone was having similar problems :)
Not possible to change this in MediaTemple (every time the (dv) restarts, it resets this value)
I fixed it by including this line in the default content's index.php
<?php
if ($_SERVER['SERVER_NAME'] == 'clintonmontague.co.uk' )
{
header ('Location: http://www.clintonmontague.co.uk/');
}
?>

Resources