为什么 nginx 将根文件夹设置到错误的位置?
why does nginx sets root folder to wrong location?
我想在我的机器上有两台服务器,一台私有的,只能在 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
。这怎么可能?根文件夹显然已设置。
问题是本地主机服务器运行在与我配置的相同 IP 上,以便可以重定向到这显然是不可能的(或者至少我不知道如何重定向)。
我已将可访问重定向到 127.0.0.2(将 /etc/hosts 中的行更改为 127.0.0.2 accessible
),这是本地计算机提供的另一个地址,并且在 nginx 配置文件 accessible
中进行了小的更改后允许所有 LAN IP地址(allow 192.168.1.0/32;
)一切正常(对我来说在本地机器和网络上的计算机)。
我想在我的机器上有两台服务器,一台私有的,只能在 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
。这怎么可能?根文件夹显然已设置。
问题是本地主机服务器运行在与我配置的相同 IP 上,以便可以重定向到这显然是不可能的(或者至少我不知道如何重定向)。
我已将可访问重定向到 127.0.0.2(将 /etc/hosts 中的行更改为 127.0.0.2 accessible
),这是本地计算机提供的另一个地址,并且在 nginx 配置文件 accessible
中进行了小的更改后允许所有 LAN IP地址(allow 192.168.1.0/32;
)一切正常(对我来说在本地机器和网络上的计算机)。