0

我们在 EC2 私有子网的 NGINX 上托管了 Django 应用程序,我们无法通过 AWS 应用程序负载均衡器端点访问它。下面是来自位置的配置文件/etc/nginx/sites-enabled/myserver.conf 我们在配置文件中504 Gateway timeout使用端口 80,在配置文件502 bad Gateway中使用 443。

upstream my_server {
  #server 0.0.0.0:80;
  server unix:/home/ubuntu/Desktop/star/star.sock fail_timeout=0;
}


server {
    listen 443; # default_server
    server_name 0.0.0.0;
client_max_body_size 4G;

access_log /home/ubuntu/Desktop/star/logs/nginx-access.log;
error_log /home/ubuntu/Desktop/star/logs/nginx-error.log;


location /static/ {
   root   /home/ubuntu/Desktop/star/dashboard/static/;


}


location / {


proxy_hide_header X-Frame-Options;


include proxy_params;
proxy_pass http://unix:/home/ubuntu/Desktop/star/star.sock;

}   


# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
        root /home/ubuntu/Desktop/star/dashboard/static/;
   }
   location ^~ /(css|js) {
                    root /home/ubuntu/Desktop/star/dashboard/static/;
           }

}

server {
    if ($host = 0.0.0.0) {
        return 301 https://$host$request_uri;
    } 
if ($host = 0.0.0.0) {
    return 301 https://$host$request_uri;
}

listen 443;
server_name 0.0.0.0;
return 404;


}   
4

1 回答 1

0

将您的配置更改为以下内容:

server {
    listen 80 default_server;
    server_name mysite.localhost;

client_max_body_size 4G;

access_log /home/ubuntu/Desktop/star/logs/nginx-access.log;
error_log /home/ubuntu/Desktop/star/logs/nginx-error.log;


location /static/ {
   root   /home/ubuntu/Desktop/star/dashboard/static/;


}


location / {


proxy_hide_header X-Frame-Options;


include proxy_params;
proxy_pass http://unix:/home/ubuntu/Desktop/star/star.sock;

}   


# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
        root /home/ubuntu/Desktop/star/dashboard/static/;
}
location ^~ /(css|js) {
                 root /home/ubuntu/Desktop/star/dashboard/static/;
}

}

请注意,您已经在其中配置了 location 和 root 指令:

location /static/ {
   root   /home/ubuntu/Desktop/star/dashboard/static/

确保文件位于正确的目录中,因为静态的结果路径将是/home/ubuntu/Desktop/star/dashboard/static/static/

于 2020-06-09T16:12:16.367 回答