我想在一个服务上运行多个网站,问题是两个域名都重定向到 domain1
域名1.com.conf
server {
listen 80;
listen [::]:80;
root /var/www/domain1;
index index.php index.html;
server_name domain1.com www.domain1.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
域名2.com.conf
server {
listen 80;
listen [::]:80;
root /var/www/domain2;
index index.php index.html;
server_name domain2.com www.domain2.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
答案1
这是我的 nginx 虚拟主机配置之一。这个配置有效,所以我认为它真的归功于那些神秘的 fastcgi 参数。
server {
listen 80;
server_name collect.local;
index index.php index.html index.htm;
root /var/www/html/collectd-html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我会怀疑这些......
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;