以下是我的 Nginx.conf -
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /usr/local/nginx/conf/sites-enabled/*;
}
我的站点可用配置 -
server {
listen 80;
server_name 1.2.3.4;
#server_name abc.in;
access_log /usr/local/nginx/logs/abc.access.log;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/abc;
}
}
在浏览器中,输入 IP 地址后,会出现两个斜杠“//”,并显示消息“此网页有重定向循环”。有人能帮我找出问题所在吗?
谢谢。
答案1
尝试阅读文档:http://wiki.nginx.org/HttpProxyModule
传递请求时,nginx 会用 proxy_pass 指令中指示的 URI 部分替换与位置相对应的 URI 部分。
您应该在 abc 后面添加尾部斜杠“/”,以确保转换后不会丢失它,否则您将得到 /abcindex.html,而不是 /abc/index.html。