将所有请求从一个端口转发到另一个 nginx
forwarding all requests from one port to another nginix
我能知道如何将来自端口 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 are not redirecting to https://myexample.com
将 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;
}
我能知道如何将来自端口 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 are not redirecting to https://myexample.com
将 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;
}