2013-12-08 21 views
0

Iam新增了nginx。nginx:如何讓nginx指向django

我配置了nginx,gunicorn和django。

當我啓動nginx的,它提供了一個誤差, 404未找到 的nginx/1.1.19

,因爲它不指向DJANGO。

現在我需要指出nginx到django(使用gunicorn作爲中間件)在使用位置或根的conf文件中。

誰能告訴我如何指出nginx的django。

謝謝

回答

0

我得跑很多這樣的應用程序:

server { 
    # listen, statics, media, etc 

    location/{ 
     proxy_pass http://127.0.0.1:8000; # Gunicorn Server 
    } 
} 
+0

我已經試過了。但沒有變化。 – user3040345

0

首先,你需要真正有gunicorn進程在運行。手動完成此操作,或者最好使用流程管理工具(例如supervisord)。下面是一個Django項目運行過程gunicorn樣本supervisord腳本:

[program:example] 
user=ubuntu 
group=ubuntu 
directory=/home/ubuntu/dev/example 
command=python manage.py run_gunicorn -c gunicorn_config.py 
autostart=true 
autorestart=true 
redirect_stderr=True 

然後,你需要一個適當的nginx的conf。下面是一個基於生產中運行的網站的最小樣本:

server { 
    listen 80; 
    listen [::]:80 default_server ipv6only=on; 
    server_name example.com; 

    location/{ 
     proxy_pass http://localhost:8000; 
     proxy_redirect off; 
     proxy_set_header Host $host; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 
    # use this if you're serving static assets locally 
    location /static/ { # make sure this is your STATIC_ROOT 
     alias /home/ubuntu/dev/example/static/; 
     access_log off; 
    } 
} 
+0

對不起,這不適合我。 – user3040345

+0

我需要指出nginx使用位置或根目錄的django。請在這裏建議我。 – user3040345

+0

您是否必須設置gunicorn以使用您在此處配置的nginx配置在端口8080上運行? – HelloW