我想在我的ubuntu VPS上使用nginx主持两个网站。所以我创建了两个默认配置副本:domain1.com
和domain2.com
为domain1.com配置:
server {
listen 80 ;
listen [::]:80 ;
root /home/sher/ftp/www/public;
server_name domain1.com www.domain1.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
如果用户在浏览器中输入www.domain1.com
,他会看到domain1
网站。但如果他在没有www
的情况下点击它,他会看到domain2.com
。我已经从这两个配置文件中创建了符号链接到sites-enabled
。
P.S:我为域名1设置listen
到default_server
,似乎问题已解决,但我不确定它是否是正确的方法。