【发布时间】:2021-09-15 04:24:41
【问题描述】:
我正在尝试使用 nginx 服务器部署我的 angular 应用程序。我遇到的问题是,当我访问该网站时,我需要重定向到特定位置,在这种情况下,我需要重定向到 mydomain.com/shop,当我进入该站点时,它会进入循环并开始输入 mydomain.com//shop/shop/shop/shop/shop……
这是我的代码。
server {
listen 443 ssl;
ssl_certificate C:/nginx/ssl/cc.crt;
ssl_certificate_key C:/nginx/ssl/pkc.key;
server_name mydomain.com www.mydomain.com;
return 301 https://$host$request_uri/shop;
}
server {
listen 443 ssl;
client_max_body_size 200M;
ssl_certificate C:/nginx/ssl/cc.crt;
ssl_certificate_key C:/nginx/ssl/pkc.key;
server_name mydomain.com www.mydomain.com;
location / {
root html/myApp;
try_files $uri $uri/ /index.html;
}
location /api/ {
client_max_body_size 200M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass https://127.0.0.1:4000/;
proxy_redirect off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
我该如何解决?提前致谢
【问题讨论】:
-
删除第一个
server块。将location = / { return 301 /shop; }添加到第二个server块中。 -
完美运行!谢谢,添加为答案
标签: angular nginx nginx-config nginx-location