这是我的虚拟主机配置。我不确定,但这是定义事物的理想方式吗?
对于每个域/子域,我都添加了一个位置〜/ .php指令。我应该在全局nginx.conf中添加它而不是为我添加的每个域单独指定吗?
示例配置: -
server {
listen 80;
server_name example.com;
location / {
root /var/www/example.com;
index index.php;
}
location ~ \.php$ {
root /var/www/example.com/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_read_timeout 30000;
#fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
server {
listen 80;
server_name www.example.net;
location / {
root /var/www/example.net/;
index index.php;
}
location ~ \.php$ {
root /var/www/example.net/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_read_timeout 30000;
# fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
答案 0 :(得分:0)
您无法将location
置于server
块之外。您可以做的最好的事情是将重复的部分放入文件和include
该文件。
此外,通常你不要在每个root
内声明location
指令,在server
内声明一次。
并且,BTW,index
指令可能在server
块之外,在这种情况下,它会影响没有自己的server
指令的所有index
块。< / p>
所以这里的配置与你的保存完全相同,但重复次数较少。
index index.php;
server {
listen 80;
server_name example.com;
root /var/www/example.com;
include location-php;
}
server {
listen 80;
server_name example.net;
root /var/www/example.net;
include location-php;
}
和location-php
文件:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}