我只是从nginx开始,并尝试在同一端口上以相同的根目录运行不同的站点。
想象一下文件结构如下:
rootPath/ -> website1-folder/index.html
|
-> website2-folder/index.html
我尝试在该上下文中使用location context
和root
指令,因此,我的nginx.config看起来像
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {}
http {
include mime.types;
server{
listen 4444;
server_name xx.xx.xx.xx;
index index.html index.htm;
location / { # this location did work :)
return 404 "Not found!";
}
location /first { # hier I got 404
root /home/websites/web1;
}
location /second { # hier I got 404
root /home/websites/web2;
}
}
我也尝试使用alias
指令,因此我的配置文件如下:
http {
include mime.types;
server{
listen 4444;
server_name xx.xx.xx.xx;
index index.html index.htm;
root /home/websites;
location / { # this location did work :)
return 404 "Not found!";
}
location /first { # hier I got 404
alias /web1; # the '/' refers to the root directive, right?
}
location /second { # hier I got 404
alias /web2;
}
}
对我来说,奇怪的是,我确信位置上下文正确匹配,因为
location /second {
alias /web2;
return 200 $uri; # this prints "/second" in the browser
}
感谢您的帮助!