#超级管理人权限
sudo su
#配置本地域名
nano /etc/hosts
#添加多个域名到hosts 本件中
127.0.0.1 test.com
127.0.0.1 www.test.com
127.0.0.1 yascmf.test.com
127.0.0.1 blog.test.com
法一:
default 配置参照 ubuntu 安装 lnmp 环境
nano /etc/nginx/sites-available/default
#复制原 service 在后面添加
server {
listen 80;
listen [::]:80;
server_name blog.test.com;
root /usr/share/nginx/html/blog;
index index.php index.html index.htm index.nginx-debian.html;
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/ /html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
修改service_name 和root 成相应的路径
# 重起 nginx
service nginx restart
恭喜你,配置成功!
法二
# 或则复制default 成 blog.test.com
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/blog.test.com
编辑blog.test.com
# 添加如上service
server {
listen 80;
listen [::]:80;
server_name blog.test.com;
root /usr/share/nginx/html/blog;
index index.php index.html index.htm index.nginx-debian.html;
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;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
修改相应的service_name 和 root
# 在sites-enabled 添加链接指向
sudo ln -s /etc/nginx/sites-available/blog.test.com /etc/nginx/sites-enabled/blog.test.com
# 重起 nginx
service nginx restart
参照:
albertogrespan.com/blog/running-multiple-domains-or-subdomains-in-nginx-with-server-blocks/
yanue.net/post-157.html
ref:nginx 配置说明
www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html
www.cnblogs.com/xiaogangqq123/archive/2011/03/04/1971002.html