您试图让nginx + gunicorn + django网站启动并运行/它在开发模式下运行良好没有错误或任何事情。配置nginx以便使用以下参数进行部署
upstream my-backend {
server localhost:8000 fail_timeout=0;
}
server {
listen 80;
root /home/wakwanza/Cod/NP/ASUT;
keepalive_timeout 5;
location /site_media/ {
autoindex on;
access_log off;
}
location /static/ {
autoindex on;
access_log off;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE_HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-FORWARDED-PROTOCOL $scheme;
proxy_redirect off;
proxy_pass http://my-backend;
}
}
我的gunicorn是从django应用程序中调用的: python manage.py run_gunicorn 收集我的静态文件到... / ASUT / site_media / static后我这样做了 只适用于开发模式。 我试过用
代替location指令 location /static/ {
autoindex on;
access_log off;
alias /home/wakwanza/Cod/NP/ASUT/site_media/;
}
但是我的静态资产仍未提供服务所有css / js / img文件夹都没有被普通网站看到,但是对于管理部分他们显示确定。
答案 0 :(得分:2)
通过更改settings.conf
对其进行排序STATIC_URL = "/static/"
和nginx.conf到
upstream app_server {
server localhost:8000 fail_timeout=0;
# For a TCP configuration:
# server 192.168.0.7:8000 fail_timeout=0;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# path for static files
#root /home/wakwanza/Cod/NP/ASUT/site_media/static;
location /static/ {
autoindex on;
alias /home/wakwanza/Cod/NP/ASUT/site_media/static/;
}
location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_pass_header Server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
error_page 500 502 503 504 /500.html;
}