【问题标题】:forwarding all requests from one port to another nginix将所有请求从一个端口转发到另一个 nginx
【发布时间】:2017-01-22 20:56:30
【问题描述】:

请问如何将所有来自端口 80 的请求转发到 443? 我的代码:

server {
        listen 80;

        root /var/www/html/;
        index index.html index.htm index.php;
        server_name myexample.com;

      location / {

              proxy_pass http://myexample.com:443/;

      }
}

server {

        listen 443;

        root /var/www/html/;
        index index.html index.html index.php;
        server_name myexample.com;
}

但对http://myexample.com 的请求不会重定向到https://myexample.com

【问题讨论】:

  • 为什么要proxy_pass,什么时候可以/应该重定向到HTTPS?
  • 我认为 proxy_pass 会做转发。
  • 是的。它会。但是浏览器和网站之间的连接仍然是 HTTP(未加密)。如果您打算加密连接,则应将 HTTP 重定向到 HTTPS,而不是 proxy_pass。
  • 我想学习如何将 http 重定向到 https .. 你能解释一下吗?
  • 请看答案

标签: apache nginx webserver sysadmin nginx-location


【解决方案1】:

将 HTTP 重定向到 HTTPS

server {
    listen 80;        
    server_name myexample.com;
    return  301 https://$host$request_uri;
}

server {
    listen 443;
    root /var/www/html/;
    index index.html index.html index.php;
    server_name myexample.com;
}

【讨论】:

  • 非常感谢..它正在工作..我能知道什么是学习 nginx 的最佳书籍或资源吗?
  • 请在您最喜欢的书店(例如 amazon、packt)上找到它们。如果这回答了您的问题,请接受为正确答案。
  • 搜索“nginx”。
猜你喜欢
  • 2017-05-20
  • 2021-11-04
  • 1970-01-01
  • 2013-04-09
  • 1970-01-01
  • 2012-04-24
  • 2016-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多