我正在运行nginx 0.8.44,我有两个uwsgi(0.9.5.4)实例。 一个用于我的Django站点,另一个运行Trac。
我有Django设置为location / { ... } ,Trac是location /trac { ... }但是当我去http://mysite/trac ,它给Trac / URL的/ trac部分。 所以我基本上得到一个404,因为Trac正在寻找它的根目录下的URL是/ trac。 它去的页面说
Error: Not Found No handler matched request to /trac
而CSS样式表不能在那个页面上工作。 但Trac的典型部分就像“View Tickets”和“Wiki”链接。
但是,如果我将Trac的位置更改为/,则完美。 在nginx或uwsgi中有没有办法将url的“位置”部分发送给应用程序? 这也发生在Django,如果它的位置不是/。
我以前使用mod_wsgi使用Apache,并能够做到这一点,没有任何大惊小怪。
对于那些search,
与fastcgi(我想,以类似的方式为wsgi),也可以这样做,类似于http://wiki.nginx.org/FcgiZope :
location /trac { fastcgi_pass unix:/path/to/socket; if ($uri ~ ^/trac/(.*)) { set $path_info /$1; } include fastcgi_params; fastcgi_param SCRIPT_NAME "/trac"; fastcgi_param PATH_INFO $path_info; }
; 或者, if没有额外的if :
location ~ ^/trac(?<path_info>/.*)$ { fastcgi_pass unix:/path/to/socket; include fastcgi_params; fastcgi_param SCRIPT_NAME "/trac"; fastcgi_param PATH_INFO $path_info; }
。
我最终设置了子域名。
所以对于trac,我使用trac.mydomain.com。
我没有find一种方法来做到这一点,没有子域,但它可能是可能的。 这只是最简单的。
对于阅读此内容的任何人,您需要将任何子域添加到您的DNS。 而对于nginxconfiguration你使用这样的东西:
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; } }