Nginx给出太多重定向错误-认为它可能与location /中的proxy_pass有关,因为当我更改它时,偶尔会收到服务器错误400或500,但没有解决方法:(我正在使用AWS ec2实例使用nginx。我可以访问***。com / static /文件夹,而没有重定向问题。
我为上游尝试了许多不同的服务器,并且完成了关于stackoverflow / digitalocean的几乎所有建议的解决方案。我是nginx的新手,所以我很可能犯了一个简单的错误。这是我的配置:
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
##
# Gzip Settings
##
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
include /etc/nginx/conf.d/*.conf;
upstream serv {
server 127.0.0.1:80;
}
server {
listen 443 ssl http2;
server_name www.***.com;
access_log /var/log/nginx/***.com.access.log;
error_log /var/log/nginx/***.com.error.log;
ssl on;
ssl_certificate /etc/letsencrypt/live/www.***.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.***.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
return 301 https://***.com$request_uri;
}
server {
listen 443 ssl http2;
server_name ***.com;
#server_name_in_redirect on;
access_log /var/log/nginx/***.com.access.log;
error_log /var/log/nginx/***.com.error.log;
ssl on;
ssl_certificate /etc/letsencrypt/live/***.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/***.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://serv/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
location /static/ {
autoindex on;
alias /home/ubuntu/foo/var/www/bar/static/;
}
}
server {
listen 80;
server_name ***.com;
location / {
return 301 https://***.com/$request_uri;
}
}
}