长话短说:
我的工作站托管文件(OSX 10.12):
1.1.1.1 www.ambrogio.prd
1.1.1.1 www.example.com
我的NGINX网络服务器根目录:
/无功/网络/ HTML /
子文件夹我将www.example.com指出: /var/www/html/example.com
我的NGINX / ect / nginx / sites-available / default:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
#my NGINX web root for testing purposes
server_name ambrogio.prd;
location / {
try_files $uri $uri/ =404;
}
#my wannabe www.example.com
server_name www.example.com;
location ^~ /example.com {
alias /var/www/html/example.com;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
autoindex on;
}
}
我找到了各种已解决的方案,like this one,我还没有得到的是如何确保在我的工作站浏览器中输入www.example.com时,我的NGINX指向我/var/www/html/example.com而不是/ var / www / html
谢谢!
已解决: [感谢@Richard Smith]
我需要为每个server_name分别使用服务器块。请参阅here for more info about issues like this。
这是我的NGINX / ect / nginx / sites-available / default更新配置:
server {
#each *server_name domain_name.ext* now has it's own separate server{} block
listen 80;
#my now-working www.example.com domain, with virtual hosts from my work station on Mac
server_name example.com www.example.com;
root /var/www/html/example.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}