我想在我的機器上有兩臺服務器,一臺是私有的,只能在127.0.0.1上本地訪問,另一臺在局域網上可見(它是根文件夾是私有服務器的子文件夾)。所以我在站點中創建了兩個配置文件並將它們鏈接到啓用站點的文件夾。文件accessible
:爲什麼nginx將根文件夾設置爲錯誤位置?
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;
}
}
之後,使http://accessible/被轉發到127.0.0.1我已經更新了/ etc/hosts文件:127.0.0.1 accessible
是行。
現在,當我嘗試連接到http://localhost/,一切正常,我得到/usr/share/nginx/html/index.html
預期。但是當我嘗試連接到http://accessible/時,會顯示相同的文件/usr/share/nginx/html/index.html
。這怎麼可能?根文件夾顯然已設置。