gpt4 book ai didi

nginx - 在 nginx 中重定向到主页

转载 作者:行者123 更新时间:2023-12-04 03:12:16 25 4
gpt4 key购买 nike

我有以下 nginx 服务器 block 。

server {
listen 80;
server_name myapp.io www.myapp.io;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;

server_name myapp.io www.myapp.io;

ssl_certificate /etc/letsencrypt/live/myapp.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myapp.io/privkey.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:EC$
ssl_session_timeout 1d;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

location ~ /.well-known {
allow all;
}

location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "";
proxy_set_header Proxy "";
proxy_pass https://127.0.0.1:3000;

# These three lines added as per https://github.com/socketio/socket.io/issues/1942 to remove sock$

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

现在,我想做以下重定向:

  1. 保持重定向 http://anythinghttps://anything

  2. https://www.myapp.iohttp://www.myapp.io 重定向到 https://www. myapp.io/home

有谁知道如何修改我的服务器 block 来实现这一点?

编辑 1: enter image description here

最佳答案

您应该添加一个 location =/ block 以强制根 URI 到 home。例如:

server {
listen 443 ssl;

server_name myapp.io www.myapp.io;

ssl_certificate ...;
ssl_certificate_key ...;
...

location = / {
return 301 /home;
}

location ~ /.well-known {
allow all;
}

location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "";
proxy_set_header Proxy "";
proxy_pass https://127.0.0.1:3000;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

关于nginx - 在 nginx 中重定向到主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44093371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com