【问题标题】:nginx proxy from subdomain to url从子域到 url 的 nginx 代理
【发布时间】:2015-12-14 19:23:56
【问题描述】:

我的配置:

server {
    listen 80;
    listen 443 spdy;
    server_name subdomain.domain.com;
    add_header Alternate-Protocol  443:npn-spdy/3.1;

    include custom.d/ssl-redirect.conf;

    ssl_certificate /etc/ssl/domain.com/domain_com-nginx.crt;
    ssl_certificate_key /etc/ssl/domain.com/domain_com.key;

    access_log /var/log/nginx/domain_com.access.log geo;
    error_log /var/log/nginx/domain_com.error.log error;

    set $fpm_pool domain.com;
    root /home/domain.com/htdocs/domain_com/public;

    index index.html index.php;

    location / {
        proxy_pass https://domain.com/mypath;
    }

    include custom.d/restrictions.conf;
    include custom.d/fpmstatus.conf;
}

我有https://domain.com/mypath 网址。 我想在调用 subdomain.domain.com 时观看这个 当我打电话给 subdomain.domain.com/sompage。在可能会抛出https://domain.com/mypath/sompage

【问题讨论】:

    标签: redirect nginx proxy


    【解决方案1】:

    您只需要添加一个返回,最好是这里的 301 状态代码:

    return 301 https://domain.com/mypath$request_uri;

    在您的代码中可能如下所示:

    server {
        listen 80;
        listen 443 spdy;
        server_name subdomain.domain.com;
        add_header Alternate-Protocol  443:npn-spdy/3.1;
    
        include custom.d/ssl-redirect.conf;
    
        ssl_certificate /etc/ssl/domain.com/domain_com-nginx.crt;
        ssl_certificate_key /etc/ssl/domain.com/domain_com.key;
    
        access_log /var/log/nginx/domain_com.access.log geo;
        error_log /var/log/nginx/domain_com.error.log error;
    
        set $fpm_pool domain.com;
        root /home/domain.com/htdocs/domain_com/public;
    
        index index.html index.php;
    
        return 301 https://domain.com/mypath$request_uri;
    
        include custom.d/restrictions.conf;
        include custom.d/fpmstatus.conf;
    }
    

    【讨论】:

    • 谢谢!我不想重定向。我想在浏览器上查看 url subdomain.doamin.com
    • 据我所知,只要两个 URL 上的内容不相同,就不可能产生这种行为。
    猜你喜欢
    • 2016-04-12
    • 2016-07-29
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多