【问题标题】:Rewrite rule for NginxNginx 的重写规则
【发布时间】:2015-08-20 14:37:03
【问题描述】:

我得到了带有 HTTP(80 端口)和 HTTPS(443)的 Nginx 服务器。但它在路由器后面,端口转发就像 HTTP 的 17014 和 HTTPS 的 17004 一样。从 HTTP 到 HTTPS 的重定向效果很好,但我在请求 HTTPS 时遇到问题。例如,当我要去“https://domain:17004”时,我应该看到我的应用程序,但只有在我要去“https://domain:port/panel_admin/login”时才能看到它。如何编写正确的重写规则之类的?这是我的实际配置:

server {
    listen         80;
    listen         [::]:80;
    rewrite ^ https://strona:port_1$request_uri? permanent; 
}
server {
    listen 443 ssl;
    ssl_certificate /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.cert;
    ssl_certificate_key /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.key;

    location / {
       proxy_pass http://localhost:4000;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
    }

    location /static {
       alias /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/static/;
    }
}

【问题讨论】:

  • 你有配置监听443端口到外部并代理4000端口。17004端口在哪里? port_1 是什么?

标签: nginx rewrite


【解决方案1】:

我解决了这个问题。正确的配置看起来像

server {
listen         80;
listen         [::]:80;
rewrite ^ https://strona:port_https$request_uri? permanent;
}
server {
listen 443 ssl;
ssl_certificate /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.cert;
ssl_certificate_key /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/cert/ssl.key;

location / {
   proxy_pass http://localhost:4000;
   proxy_set_header Host $host:port_http;
   proxy_set_header X-Real-IP $remote_addr;
}

location /static {
   alias /var/projekt/release_candidate/tags/0.4.1/trunk/zlight/webapp/static/;
}
}

所以没有重写。 :)

【讨论】:

    猜你喜欢
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    • 2015-03-04
    • 2013-10-12
    相关资源
    最近更新 更多