我正在尝试向 nginx 添加第二个域名。在 domain2.com 中访问 css 等静态文件是可以的,但访问 php 脚本(例如 domain2.com/index.php)将被 302 重定向到 domain1.com(例如 domain1.com/index.php),所以我想断点一定在该location ~ \.php$
部分,但我不确定它在哪里。我在这里卡了很久,我哪里做错了?[OS:windows 2008;Nginx:1.0.12]
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 50m;
gzip on;
server {
listen 80;
server_name _;
server_name_in_redirect off;
location / {
root F:/Web/nginx/html/;
index index.html;
}
}
include F:/Web/nginx/vhosts/*.conf;
}
F:/Web/nginx/vhosts/domain1.com.conf
server {
listen 80;
server_name domain1.com;
charset utf-8;
location / {
root F:/domain1;
index index.php;
try_files $uri $uri/ /index.php?$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME F:/domain1/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
F:/Web/nginx/vhosts/domain2.com.conf
server {
listen 80;
server_name domain2.com;
charset utf-8;
location / {
root F:/domain2;
index index.php;
try_files $uri $uri/ /index.php?$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME F:/domain2/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
更新:
我找到原因了。不是nginx配置问题,是php-cgi配置问题。我设置了,doc_root='F:/domain1'
所以一直重定向。
希望能够帮助再次遇到此问题的人。