gpt4 book ai didi

angular - Nginx网址重写仅适用于/

转载 作者:行者123 更新时间:2023-12-02 21:02:11 25 4
gpt4 key购买 nike

将我的 Angular 应用程序移植到nginx

我的网址重写配置仅适用于/位置。如果在浏览器中转到localhost:5000/login,则会收到404错误。

这是我的nginx.conf

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

server {
listen 80;
root /usr/share/nginx/html;

location / {
root /usr/share/nginx/html;
index index.html;

try_files $uri $uri/ /usr/share/nginx/html/index.html;
}


}
}

日志
2020/02/05 06:44:29 [error] 6#6: *1 open() "/usr/share/nginx/html/login" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /login HTTP/1.1", host: "localhost:5000"
172.17.0.1 - - [05/Feb/2020:06:44:29 +0000] "GET /login HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"

我想念什么?

最佳答案

您需要使用应用程序根文件设置try_files

try_files $uri $uri/ /usr/share/nginx/html/index.html;

引用: https://angular.io/guide/deployment

关于angular - Nginx网址重写仅适用于/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60070558/

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