mod_wsgi hello world failing on ubuntu 14.04

753 views
Skip to first unread message

David Sargrad

unread,
Sep 25, 2014, 9:04:57 AM9/25/14
to mod...@googlegroups.com
I am trying to follow the instructions for running the mod_wsgi hello world application:
https://code.google.com/p/modwsgi/wiki/WhereToGetHelp

I installed apache2 and libapache2-mod-wsgi
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi

My wsgi hello world:
/var/www/yo/public_html# cat yo.wsgi
def application(environ, start_response):
    status
= '200 OK'
    output
= 'Yo World!'

    response_headers
= [('Content-type', 'text/plain'),
                       
('Content-Length', str(len(output)))]

    start_response
(status, response_headers)

   
return [output]


My virtualhost:
/etc/apache2/sites-available# cat yo.conf
<VirtualHost *:80>
   
ServerName yohost
#    WSGIDaemonProcess cwpmash user=ubuntu group=ubuntu threads=5
   
WSGIScriptAlias /yo /var/www/yo/public_html/yo.wsgi
   
DocumentRoot /var/www/yo/public_html
   
<Directory /var/www/yo/public_html>
#        WSGIProcessGroup cwpmash
#        WSGIApplicationGroup %{GLOBAL}
       
Order allow,deny
       
Allow from all
   
</Directory>
</
VirtualHost>

I've enabled info logging in apache (rather than warn).

I've enabled the site:
/etc/apache2/sites-available# ls ../sites-enabled/
000-default.conf  yo.conf




My apache2 error log shows the following on apache restart:

[Thu Sep 25 13:04:46.211520 2014] [:info] [pid 2305:tid 139868472567680] mod_wsgi (pid=2305): Destroying interpreters.
[Thu Sep 25 13:04:46.211603 2014] [:info] [pid 2305:tid 139868472567680] mod_wsgi (pid=2305): Cleanup interpreter ''.
[Thu Sep 25 13:04:46.211907 2014] [:info] [pid 2306:tid 139868472567680] mod_wsgi (pid=2306): Destroying interpreters.
[Thu Sep 25 13:04:46.211976 2014] [:info] [pid 2306:tid 139868472567680] mod_wsgi (pid=2306): Cleanup interpreter ''.
[Thu Sep 25 13:04:46.216683 2014] [:info] [pid 2305:tid 139868472567680] mod_wsgi (pid=2305): Terminating Python.
[Thu Sep 25 13:04:46.217228 2014] [:info] [pid 2306:tid 139868472567680] mod_wsgi (pid=2306): Terminating Python.
[Thu Sep 25 13:04:46.220709 2014] [:info] [pid 2305:tid 139868472567680] mod_wsgi (pid=2305): Python has shutdown.
[Thu Sep 25 13:04:46.221243 2014] [:info] [pid 2306:tid 139868472567680] mod_wsgi (pid=2306): Python has shutdown.
[Thu Sep 25 13:04:46.226124 2014] [core:info] [pid 2302:tid 139868472567680] AH00096: removed PID file /var/run/apache2/apache2.pid (pid=2302)
[Thu Sep 25 13:04:46.226199 2014] [mpm_event:notice] [pid 2302:tid 139868472567680] AH00491: caught SIGTERM, shutting down
[Thu Sep 25 13:04:47.348730 2014] [mpm_event:notice] [pid 2484:tid 140368719771520] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Thu Sep 25 13:04:47.348963 2014] [mpm_event:info] [pid 2484:tid 140368719771520] AH00490: Server built: Jul 22 2014 14:36:38
[Thu Sep 25 13:04:47.349000 2014] [core:notice] [pid 2484:tid 140368719771520] AH00094: Command line: '/usr/sbin/apache2'
[Thu Sep 25 13:04:47.349215 2014] [:info] [pid 2487:tid 140368719771520] mod_wsgi (pid=2487): Initializing Python.
[Thu Sep 25 13:04:47.351673 2014] [:info] [pid 2488:tid 140368719771520] mod_wsgi (pid=2488): Initializing Python.
[Thu Sep 25 13:04:47.371271 2014] [:info] [pid 2487:tid 140368719771520] mod_wsgi (pid=2487): Attach interpreter ''.
[Thu Sep 25 13:04:47.372339 2014] [:info] [pid 2488:tid 140368719771520] mod_wsgi (pid=2488): Attach interpreter ''.


I'm sure the SIGTERM is not good, and perhaps is at the core of the problem. This seems like a very simple configuration, yet I cant get it working. Unfortunately the error log is not that informative, at least to an untrained eye.

Please help. What am I doing wrong?

Graham Dumpleton

unread,
Sep 25, 2014, 9:32:40 AM9/25/14
to mod...@googlegroups.com
You haven't explained how it is failing so is hard to say.

What actual URL are you using to access the site?

What is the error the browser returns?

Is 'yohost' a resolvable hostname?

Also see comments below.

On 25/09/2014, at 9:04 PM, David Sargrad <davids...@hotmail.com> wrote:

I am trying to follow the instructions for running the mod_wsgi hello world application:
https://code.google.com/p/modwsgi/wiki/WhereToGetHelp

I installed apache2 and libapache2-mod-wsgi
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi

My wsgi hello world:
/var/www/yo/public_html# cat yo.wsgi
def application(environ, start_response):
    status = '200 OK'
    output = 'Yo World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]

    start_response(status, response_headers)

    return [output]

As a general rule, if using WSGIScriptAlias, you should not be placing the WSGI script file in the DocumentRoot directory, especially where you have mounted it at a sub URL as the source code for the application is downloable via the DocumentRoot directory.


My virtualhost:
/etc/apache2/sites-available# cat yo.conf
<VirtualHost *:80>
    ServerName yohost

Is 'yohost' a valid name which is resolvable?

#    WSGIDaemonProcess cwpmash user=ubuntu group=ubuntu threads=5
    WSGIScriptAlias /yo /var/www/yo/public_html/yo.wsgi

This indicates you should be access it as:


    DocumentRoot /var/www/yo/public_html

Because you are stick your code in DocumentRoot and mounting at sub URL, I can download the source code by accessing:


Thus why you shouldn't put it there.
The SIGTERM message is normal. That is what you will see when Apache is being restarted.

Please help. What am I doing wrong?

Need to know what is failing first before can guess.

Graham

David Sargrad

unread,
Sep 25, 2014, 9:42:37 AM9/25/14
to mod...@googlegroups.com
Thank you for the fast response.

The failure is that I can not browse to my hello world app, and see the expected response "Yo World".

yohost is in my hosts files (tied currently to 127.0.0.1).. pingable and resolvable.


i've tried to get to the site using wget
wget http://yohost/yo

I am able to wget the base apache page
wget http://yohost

Should I see anything in a log somewhere that would indicate that yo.wsgi has been loaded? Is the SIGTERM that you see in the error.log related to wsgi? I did notice that I still see that even when i disable my yohost site. It does seem however that mod_wsgi is running, starting pything, and attaching interpreters. I would have thought that some log would say "mod_wsgi... loading yo", or something akin to that.
...

Graham Dumpleton

unread,
Sep 25, 2014, 9:52:43 AM9/25/14
to mod...@googlegroups.com
On 25/09/2014, at 9:42 PM, David Sargrad <davids...@hotmail.com> wrote:

Thank you for the fast response.

You were very lucky, I am actually on holidays with limited Internet access. :-)

So quick responses with as much detail as possible on the specific questions I ask will get you a quick answer. If not, then I may not be online for a another day or so.

The failure is that I can not browse to my hello world app, and see the expected response "Yo World".

But what error do you see in the web browser? The actual test of the message or any HTTP status code will help to understand what is failing.

yohost is in my hosts files (tied currently to 127.0.0.1).. pingable and resolvable.

i've tried to get to the site using wget
wget http://yohost/yo

I am able to wget the base apache page
wget http://yohost

Should I see anything in a log somewhere that would indicate that yo.wsgi has been loaded?

With 'info' level yes, but you aren't seeing it.

Is the SIGTERM that you see in the error.log related to wsgi?

As I said, that is normal. It is Apache saying it received a signal to restart, likely after you changed the configuration and told it to reload.

I did notice that I still see that even when i disable my yohost site. It does seem however that mod_wsgi is running, starting pything, and attaching interpreters. I would have thought that some log would say "mod_wsgi... loading yo", or something akin to that.

Find the Apache access log. Is there anything being added to that when you attempt requests?

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

David Sargrad

unread,
Sep 25, 2014, 10:04:47 AM9/25/14
to mod...@googlegroups.com
So In the error log I see the following:

[Thu Sep 25 13:57:44.291610 2014] [core:info] [pid 3148:tid 139882152310528] [client 127.0.0.1:38363] AH00128: File does not exist: /var/www/html/yo

The access log shows a "404":
127.0.0.1 - - [25/Sep/2014:13:57:44 +0000] "GET /yo HTTP/1.1" 404 490 "-" "Wget/1.15 (linux-gnu)"

This seems to suggest that apache is looking in the default document root, rather than at the "yo virtual host".

Just as an aside, I am trying to get the "hello  world" working, before I get my "flask app" working: trying to crawl before I walk. :)



On Thursday, September 25, 2014 9:04:57 AM UTC-4, David Sargrad wrote:
...

David Sargrad

unread,
Sep 25, 2014, 10:06:24 AM9/25/14
to mod...@googlegroups.com
The same request within the browser also shows that "Not Found The requested URL /yo was not found..."




On Thursday, September 25, 2014 9:04:57 AM UTC-4, David Sargrad wrote:
...

Graham Dumpleton

unread,
Sep 25, 2014, 10:12:43 AM9/25/14
to mod...@googlegroups.com
What other VirtualHost definitions are setup for port 80, and especially with the same ServerName.

You can't have more than for same server name and port combination. Most likely it is ignoring your added one and using a previous one.

Also do check if you new one is even being loaded by adding a syntax error into the file. To do this just add a new line to file with:

  This is a syntax error.

and restart Apache. If it still starts, the file isn't even being loaded.

Graham

David Sargrad

unread,
Sep 25, 2014, 10:16:04 AM9/25/14
to mod...@googlegroups.com
I did a fresh install of both apache and mod_wsgi yesterday. This is the only virtual host enabled (above and beyond the default). Though I started first with my flask app yesterday I disabled that site:


/etc/apache2/sites-enabled# ls -ltr
total 0
lrwxrwxrwx 1 root root 35 Sep 25 12:03 000-default.conf -> ../sites-available/000-default.conf
lrwxrwxrwx 1 root root 26 Sep 25 13:16 yo.conf -> ../sites-available/yo.conf

Do I need to disable the default site?

I would think not
/etc/apache2/sites-enabled# cat 000-default.conf
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>


On Thursday, September 25, 2014 9:04:57 AM UTC-4, David Sargrad wrote:
...

David Sargrad

unread,
Sep 25, 2014, 10:20:22 AM9/25/14
to mod...@googlegroups.com
Ok. I've added a syntax error intentionally (this btw was something i did b4 to verify that the site file was being loaded).. did it again just to be thorough:
service apache2 restart
 * Restarting web server apache2                                                                                      [fail]
 * The apache2 configtest failed.
Output of config test was:
AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/yo.conf:
Invalid command 'adding', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.



On Thursday, September 25, 2014 9:04:57 AM UTC-4, David Sargrad wrote:
...

Graham Dumpleton

unread,
Sep 25, 2014, 10:25:40 AM9/25/14
to mod...@googlegroups.com
If you access:


do you see the source code for the script?

If you don't it means that VirtualHost is not being used but the default is.

Also try using telnet to access the server port directly:

$ telnet yohost 80
GET /yo HTTP/1.0
Host: yohost

With multiple returns after Host line.

Anyway, time for me to go and not sure when back on next.

Graham

David Sargrad

unread,
Sep 25, 2014, 10:31:22 AM9/25/14
to mod...@googlegroups.com
Wow.. telnet shows "yo world"..
root@sensis-8930:/etc/apache2# telnet yohost 80
Trying 127.0.1.1...
Connected to sensis-8930.corp.sensis.com.
Escape character is '^]'.
GET
/yo HTTP/1.0
Host: yohost

HTTP
/1.1 200 OK
Date: Thu, 25 Sep 2014 14:31:54 GMT
Server: Apache/2.4.7 (Ubuntu)
Content-Length: 9
Vary: Accept-Encoding
Connection: close
Content-Type: text/plain

Yo World!Connection closed by foreign host.




On Thursday, September 25, 2014 9:04:57 AM UTC-4, David Sargrad wrote:
...

David Sargrad

unread,
Sep 25, 2014, 10:59:39 AM9/25/14
to mod...@googlegroups.com
Hmm. Ok with your suggestions, I've finally figured out the problem. It is indeed a problem with having the default VirtualHost enabled. I disabled that and voila everything works:

 a2dissite 000-default

I'm surprised that none of the tutorials that I've seen suggest this. They all talk about adding a virtualhost, but none seem to talk to the fact that this could interfere with the default virtualhost.

Anyways, Thanks for taking the time to help a noobie.

Now for the real work of getting my flask app integrated. :)



On Thursday, September 25, 2014 9:04:57 AM UTC-4, David Sargrad wrote:
...

Graham Dumpleton

unread,
Sep 26, 2014, 9:48:58 AM9/26/14
to mod...@googlegroups.com
What was 'yohost' really is likely the problem.

If it was a simple host name (not a FQDN) that mapped to 'localhost' or '127.0.0.1', then a client may not have sent the 'Host' header in the request. Without that being present, then server wouldn't have been able to match it to the name based virtual host and would fallback to the default virtual host (first one Apache found when reading the configuration).

Graham

Reply all
Reply to author
Forward
0 new messages