【发布时间】:2021-05-11 03:38:44
【问题描述】:
您好,我有一个完整的 django 应用程序,我将使用 gunicorn 和 nginx 在 aws ec2 上托管它。但是当我使用 gunicorn 或 python3 运行应用程序时,我的应用程序会运行并显示所有带有 css 和样式的图像。但是,每当我尝试通过 proxy_pass 为我的 django 应用程序提供 nginx 时,图像或样式或静态文件夹上的任何内容都无法访问。我的错误日志显示权限问题。但是我已经将应用程序设置为用户和组 nginx。但什么都没有显示。
- nginx.conf 上的 nginx 配置
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name example.com;
root /home/ec2-user/sites/softopark-django-cms;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /usr/share/nginx/html/softopark-django-cms/static/;
}
location /media/ {
root /usr/share/nginx/html/softopark-django-cms/media/;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://0.0.0.0:8000/;
}
}
- 我的 gunicorn 服务文件
[Unit]
Description=test
After=network.target
[Service]
User=nginx
Group=nginx
WorkingDirectory=/usr/share/nginx/html/softopark-django-cms
Environment="/home/ec2-user/Env/cms5-XkwMz5k7/bin"
ExecStart=/home/ec2-user/Env/cms5-XkwMz5k7/bin/gunicorn --workers 3 --bind 0.0.0.0:8000 cms_project.wsgi
[Install]
WantedBy=multi-user.target
- 谁能帮我解决这个问题?
我需要在 aws 上托管我的 django 应用程序,但使用 nginx 我无法做到这一点。请帮忙。
【问题讨论】:
-
Django 与直接通过 ngnix 提供静态内容无关,你应该写 stackoverflow.com/help/minimal-reproducible-example 并包含回溯
标签: django amazon-web-services nginx