假设有5个二级域名:
aaa.example.com
bbb.example.com
ccc.example.com
ddd.example.com
eee.example.com
在配置nginx的时候,server模块是这样的:
server {
listen 443 ssl http2;
server_name aaa.example.com;
root /var/www/aaa.example.com/public;
index index.php index.html index.htm;
location / {
root /var/www/aaa.example.com/public;
try_files $uri $uri/ /index.php?$query_string;
index index.php index.html index.htm;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/dev/shm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#...
#...
#...
}
问题:
1、有5个二级域名,必须要写5个server模块吗?可以写个通用的只用一个server模块吗?
2、如果写5个server模块的话,每个server模块中的location ~ \.php${ }
模块是一样的,这个location ~ \.php${ }
模块可以只写一遍来共用吗?也就是可以把它弄到server模块的上一层模块http模块去吗?
3、看到很多示例的root和index都要写两遍,server里面写一遍,下一层的location / { }
模块中再写一遍,这是为什么?