我想服务于不同的网站,基于url用户输入。例如,如果用户将转到
my-domain.pl/内容将从桌面文件夹中提供
my-domain.pl/desktop内容将从桌面文件夹中提供
my-domain.pl/mobile内容将从移动文件夹中提供
root
|
|---mobile
| |--- assets
| |---js,css,img
|
|---desktop
|--- assets
|---js,css,img我在nginx安装文件中尝试过:
server {
root /desktop
location /mobile {
root /mobile
}
location /desktop{
root /desktop
}
}但是它只适用于/路径,其余路径返回404。
我尝试添加try_files $uri index.html,但是它似乎返回这个位置的所有请求的index.html文件,例如,它也返回index.html文件而不是javascript。
我在建立nginx绝对是新的,所以任何帮助都将不胜感激。
发布于 2016-01-20 16:26:25
您需要使用alias指令而不是root:参见文档。
server {
root /;
location /desktop {
}
location /mobile {
alias /mobile;
}
}(别忘了尾随分号)
发布于 2016-01-20 16:17:12
应该避免在root块中指定location (cf )。nginx陷阱)。
你试过以下几种方法:
rootrewrite为/desktop服务配置如下所示:
server {
root /;
## this should take care of the redirect to /desktop by default:
location = / {
rewrite ^ /desktop/ redirect;
}
## this one below probably doesn't work:
# rewrite ^/$ /desktop/;
}我现在无法访问带有nginx的机器,所以我无法检查rewrite语法。另见这个答案。
https://stackoverflow.com/questions/34904926
复制相似问题