【发布时间】:2016-01-18 20:35:11
【问题描述】:
我想在我的机器上安装两台服务器,一台专用,只能在 127.0.0.1 本地访问,另一台在 LAN 上可见(它的根文件夹是专用服务器的子文件夹)。所以我在sites-available 中创建了两个配置文件,并将它们链接到sites-enabled 文件夹。档案accessible:
server {
listen 80;
root /usr/share/nginx/html/accessible/;
index index.php index.html index.htm;
server_name accessible;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/accessible/;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
和文件localhost:
server {
listen 127.0.0.1:80;
listen [::1]:80;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
之后我更新了 /etc/hosts 以便将 http://accessible/ 转发到 127.0.0.1:127.0.0.1 accessible 是该行。
现在,当我尝试连接到 http://localhost/ 时,一切正常,我按预期得到了 /usr/share/nginx/html/index.html。但是当我尝试连接到http://accessible/ 时,会显示相同的文件/usr/share/nginx/html/index.html。这怎么可能?根文件夹显然已设置。
【问题讨论】:
标签: nginx configuration