将所有请求从一个端口转发到另一个端口

时间:2016-09-14 22:53:30

标签: apache nginx webserver sysadmin nginx-location

我可以知道如何转发从端口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

1 个答案:

答案 0 :(得分:0)

将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;
}