配置Nginx反向代理时出现问题

时间:2019-01-17 09:34:37

标签: nginx synology

我正在努力配置一个简单的反向代理。

在浏览器中,我写了URL http://my_domain/my_app,然后应由nginx将其传递到我的内部应用服务器http://127.0.0.1:9000/

http://my_domain/my_app   -->   http://127.0.0.1:9000/

应用服务器收到http://127.0.0.1:9000/后,会将我重定向到http://127.0.0.1:9000/init/login,应由nginx转换回http://my_domain/my_app/init/login

http://127.0.0.1:9000/init/login   -->   http://my_domain/my_app/init/login

据我所知,nginx doc是我的配置:

location ~ ^/my_app(.*)$ {
    proxy_pass http://127.0.0.1:9000$1;
    proxy_redirect http://127.0.0.1:9000/ $scheme://$host/my_app/;
}

似乎通过翻译

可以正常使用代理通行证

http://my_domain/my_app-> http://127.0.0.1:9000/

,但我却以相反的方向重定向到http://my_domain/init/login,这是无效的。应该是http://my_domain/my_app/init/login

任何想法如何编写nginx配置?

编辑: 它是安装在Synology DSM 6.0上的Play框架网络应用,由默认的nginx服务器提供服务。 nginx的配置很大,因此这里只是服务器部分:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    gzip on;

    server_name _;

    location ~ ^/volume(?:X|USB|SATA|Gluster)?\d+/ {
        internal;

        root /;

        open_file_cache off;

        include app.d/x-accel.*.conf;
        include conf.d/x-accel.*.conf;
    }

    include app.d/www.*.conf;
    include app.d/alias.*.conf;
    include /usr/syno/share/nginx/conf.d/www.*.conf;
    include conf.d/www.*.conf;

    location = /webdefault/images/logo.jpg {
        alias /usr/syno/share/nginx/logo.jpg;
    }

    error_page 403 404 500 502 503 504 @error_page;

    location @error_page {
        root /usr/syno/share/nginx;
        rewrite (.*) /error.html break;
        allow all;
    }

    location ^~ /.well-known/acme-challenge {
        root /var/lib/letsencrypt;
        default_type text/plain;
    }

    include app.d/.location.webstation.conf*;

    location / {
        rewrite ^ / redirect;
    }

    location ~ ^/$ {
        rewrite / http://$host:5000/ redirect;
    }
}

我的Location指令包含在语句include conf.d/www.*.conf;

0 个答案:

没有答案