代理后的Nginx:避免自动重定向到内部端口

代理后的Nginx:避免自动重定向到内部端口,nginx,Nginx,我有一个设置,其中haproxy在example.com:80上侦听,并将HTTP请求代理给在服务器20080上侦听的nginx实例 nginx所做的只是从/usr/share/nginx/html提供静态文件 例如,http://example.com/doc/映射到/usr/share/nginx/html/doc/ 但是,http://example.com/doc(不带尾随斜杠)导致301重定向到http://example.com:20080/doc/: $ curl -i http:

我有一个设置,其中haproxy在example.com:80上侦听,并将HTTP请求代理给在服务器20080上侦听的nginx实例

nginx所做的只是从
/usr/share/nginx/html
提供静态文件

例如,
http://example.com/doc/
映射到
/usr/share/nginx/html/doc/

但是,
http://example.com/doc
(不带尾随斜杠)导致301重定向到
http://example.com:20080/doc/

$ curl -i http://example.com/doc
HTTP/1.1 301 Moved Permanently
Server: nginx/1.0.15
Date: Tue, 09 Dec 2014 15:10:44 GMT
Content-Type: text/html
Content-Length: 185
Location: http://example.com:20080/doc/
请注意,nginx在URL中包含了端口20080。但是,这是不需要的,因为该站点面向公众的URL是
http://example.com/
因此重定向应该是
http://example.com/doc/

向nginx解释这一点最简单的方法是什么

/etc/nginx/nginx.conf

user              nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}
server {
    listen       20080 default_server;
    include /etc/nginx/default.d/*.conf;

    root /usr/share/nginx/html;
    index index.html;

    location /doc/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/doc;
    }
}
/etc/nginx/conf.d/default.conf

user              nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}
server {
    listen       20080 default_server;
    include /etc/nginx/default.d/*.conf;

    root /usr/share/nginx/html;
    index index.html;

    location /doc/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/doc;
    }
}

nginx.conf
文件是CentOS nginx软件包版本1.0.15中的默认文件。这是一个旧版本,但我无法控制CentOS或其软件包版本。

配置您的HAProxy,或使用
端口输入重定向关闭指令。

您的HAProxy配置是什么?配置您的HAProxy,或使用
port\u in\u redirect off
directive@AlexeyTen:成功了;请将其作为答案发布,我将接受:)
port\u in\u redirect off
完成了任务!