Thursday, February 3, 2011

nginx is giving the webapp the "location" part of the url

I'm running nginx 0.8.44, and I have two uwsgi (0.9.5.4) instances. One for my Django site, the other is running Trac.

I have Django setup as location / { ... }, and Trac is location /trac { ... } But When I go to http://mysite/trac, it gives Trac the /trac part of the url. So I basically get a 404 because Trac is looking for a url under it's root that is /trac. The page it goes to says

Error: Not Found
No handler matched request to /trac

And the CSS stylesheets aren't working on that page. But the typical parts of Trac are there like the "View Tickets" and "Wiki" links.

But if I change Trac's location to /, it works perfectly. Is there some way in either nginx or uwsgi to not send the "location" part of the url to application? This also happens to Django if it's location isn't /.

I was previously using Apache with mod_wsgi, and it was able to do this without any fuss.

  • I ended up setting up subdomains.
    So for trac, I'm using trac.mydomain.com.

    I did not find a way to do this without subdomains, but it might be possible. This just ended up being the easiest.

    For anyone reading this, you need to add any subdomains to your DNS. And for nginx configuration you use something like this:

    http {
    
       upstream django {
           ip_hash;
           server 127.0.0.1:3030;
       }
    
       upstream trac {
           ip_hash;
           server 127.0.0.1:3031;
       }
    
       server {
          listen 80;
          server_name mydomain.com;
    
          location / {
              uwsgi_pass django;
              include uwsgi_params;
          }
       }
    
       server {
           listen 80;
           server_name trac.mydomain.com;
    
           location / {
               uwsgi_pass trac;
               include uwsgi_params;
           }
       }
    
    From jonescb

0 comments:

Post a Comment