【发布时间】:2022-01-05 06:12:58
【问题描述】:
我正在尝试建立一个使用 django 框架编写的简单博客站点。该网站可以正常工作,只是它不提供静态文件。我想那是因为 nginx 没有运行。但是,当我将其配置为在 80 以外的任何端口上运行时,我收到以下错误:
nginx: [emerg] bind() to 172.17.0.1:9000 failed (99: Cannot assign requested address)
当我在 gunicorn 已使用的端口上运行它时,我收到以下错误:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
我的nginx配置文件如下:
upstream django {
server 127.0.0.1:8080;
}
server {
listen 172.17.0.1:9000;
server_name my.broken.blog;
index index.html;
location = /assets/favicon.ico { access_log off; log_not_found off; }
location /assets {
autoindex on;
alias /var/www/html/mysite/assets;
}
location / {
autoindex on;
uwsgi_pass unix:///run/uwsgi/django/socket;
include /var/www/html/mysite/mysite/uwsgi_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
但是,如果我在没有启动 guincorn 的情况下运行 nginx,它会正常运行,但会出现 403 禁止错误。
按照建议的答案,我没有收到任何错误,但该网站返回 403 禁止,并且没有显示 gunicorn 应该提供的网站部分。
【问题讨论】:
-
服务器 { 听 80; server_name 172.17.0.1;
-
指定监听端口
-
使用以下设置静态文件
-
位置 /static/ { root /path/to/static }