重写nginx,以便从根目录开始解析资源
我有以下网址:重写nginx,以便从根目录开始解析资源,nginx,Nginx,我有以下网址: localhost/web app/some/path/here 如何将nginx配置为将/web app/部分视为/?我的意思是,它从文档根开始搜索some/path/here资源,而不是从webapp文件夹开始搜索。目前我有以下配置: listen 80; server_name app.client; root webclient/build/dist; index index.html; location ~ /rest/ { proxy_s
localhost/web app/some/path/here
如何将nginx配置为将/web app/
部分视为/
?我的意思是,它从文档根开始搜索some/path/here
资源,而不是从webapp
文件夹开始搜索。目前我有以下配置:
listen 80;
server_name app.client;
root webclient/build/dist;
index index.html;
location ~ /rest/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://localhost:8080;
}
location / {
try_files $uri $uri/ =404;
}
根据您的评论,您可以选择:
- Nginx的编译方式不同于
也是根指令解析的绝对路径的开始,例如:--前缀
$nginx-V[…]--前缀=/path/to[…]
server {
root /path/to/my/;
location /foo {
alias ./docs;
}
}
然后它将别名为/path/to/my/docs
- alias指令中没有将
解析为文件系统根目录的内容,您必须提供完整的目录路径/
location/web app/{alias/;}
<代码>根目录必须是绝对路径。@Deadooshka,谢谢!我尝试了localhost/web-app
,但没有成功,返回了404
。你所说的root
必须是绝对路径是什么意思?我指的是第3行root/webclient/build/dist代码>使用正向SLA实际上我的根被定义为相对于ngxinx可执行文件的路径,它看起来像这样root../。/Projects/app/app-web/src/main/webclient/build/dist代码>。有问题吗?谢谢!是的,我没有配置--prefix
(nginx-V显示--prefix=
,没有指定路径),所以我指定了从/
文件系统根目录开始的目录的完整路径。