我正在尝试为本地开发/测试设置nginx。子域加载主index.php,我无法弄清楚为什么。问题是nowingnews.localhost.com和wasob.mylocalhost.com都加载了http://mylocalhost/index.php的index.php。
以下是nowingnews.mylocalhost.com的虚拟主机配置
server {
#Nginx should listen on port 80 for requests to yoursite.com
listen 80;
server_name nowingnews.mylocalhost.com;
#Create access and error logs in /var/log/nginx
access_log /var/log/nginx/nowingnews.access_log;
error_log /var/log/nginx/nowingnews.error_log debug;
root /var/www/html/nowingnews;
#location / {
#try_files $uri $uri/ /nowingnews/index.php;
#}
#Specifies that Nginx is looking for .php files
location ~ /.*\.php$ {
include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#if (!-f $document_root$fastcgi_script_name) {
# return 404;
#}
fastcgi_index /index.php;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
# include the fastcgi_param setting
include /etc/nginx/fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
这是默认配置
server {
#Nginx should listen on port 80 for requests to yoursite.com
listen 80;
server_name localhost;
#Create access and error logs in /var/log/nginx
access_log /var/log/nginx/default.access_log;
error_log /var/log/nginx/default.error_log crit;
root /var/www/html/;
#The homepage of your website is a file called index.php
index index.php index.htm index.html;
#Specifies that Nginx is looking for .php files
location ~ /.*\.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
include fastcgi_params;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
include "/etc/nginx/sites-enabled/*";