【发布时间】:2021-11-09 05:41:58
【问题描述】:
我正在配置更改部署在 nginx 中的 angular 项目的部署。默认文件托管在 /usr/share/nginx/html 上,当我从 localhost 访问时它可以工作。但是,我想在 URL 上定义 /dev 或 /prod,它看起来像:localhost/dev 或 localhost/prod 但是当我更改 nginx 配置时它不起作用,因为它一直在 /usr/share 查找文件/nginx/html/dev
如何重写 URL 以指向静态文件所在的 /usr/share/nginx/html?
当前 nginx 位置配置:
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /dev/ {
root /usr/share/nginx/html;
#index index.html index.htm;
}
}
错误:
2021/09/14 01:43:34 [error] 75#75: *7 "/usr/share/nginx/html/dev/index.html" is not found (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /dev/ HTTP/1.1", host: "localhost:4201"
我已尝试更改配置,但遇到了一个禁止问题 配置:
location /dev/ {
#root /usr/share/nginx/html;
#index index.html index.htm;
alias /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
错误:
2021/09/14 02:11:45 [error] 92#92: *10 directory index of "/usr/share/nginx/html" is forbidden, client: 172.18.0.1, server: localhost, request: "GET /dev/ HTTP/1.1", host: "localhost:4201"
【问题讨论】:
标签: angular nginx nginx-config