我有一个django网站,在运行runserver时在我的本地计算机上运行得非常好。该网站托管在Ubuntu 12.04 LTS的Amazon EC2实例中,其中nginx为webserver。我使用fcgi和nginx一起使用django进行部署,S3用于提供静态文件。主页正确显示,但对于其他所有网址(即使不在urls.py上的网页),也会显示主页(根页/)。 我不知道发生了什么。
# urls.py (don't think anything is wrong here)
from django.contrib import admin
admin.autodiscover()
from tastypie.api import Api
from rating.myapi import ReturnNext, Rating
v1_api = Api(api_name='v1')
v1_api.register(ReturnNext())
v1_api.register(Rating())
urlpatterns = patterns('',
url(r'^$', 'fbData.newviews.home', name="home"),
url(r'^level/$', 'fbData.newviews.level_complete', name="level"),
url(r'^top/$', 'fbData.newviews.top_style', name="top"),
url(r'^facebook/', include('django_facebook.urls')),
url(r'^accounts/', include('django_facebook.auth_urls')),
(r'^api/', include(v1_api.urls)),
url(r'api/doc/', include('tastypie_swagger.urls', namespace='tastypie_swagger')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 128;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
# fastcgi_pass 121.0.0.1:3033
# listen *:80;
# listen 127.0.0.1:3033;
# listen 127.0.0.1:8080;
# listen 127.0.0.1:80;
server_name ec2-54-245-140-15.us-west-2.compute.amazonaws.com;
access_log /srv/www/test/logs/facebook-app-rating.access.log;
location / {
root /srv/www/test/facebook-app-rating;
index index.html index.htm;
fastcgi_pass 127.0.0.1:3033;
}
}
}
答案 0 :(得分:0)
我没有看到您从nginx传递到django应用程序的任何fastcgi_param
。你需要它们。要解决您的问题,您需要通过PATH_INFO
这样的
server {
...
fastcgi_param PATH_INFO $fastcgi_script_name;
}
但你也需要其他参数。您可以查看示例here或谷歌搜索。