(原创)Nginx的配置及安装二,配置多站点

1、在 /etc/nginx 下创建 vhosts 目录

mkdir /etc/nginx/vhosts

include /etc/nginx/vhosts/*;

2、在 /etc/nginx/vhosts/ 里创建一个名字为 blog.junebuy.com.conf 的文件,把以下内容拷进去(其中红色部分要根据实际情况进行修改)

server {
listen 80;
server_name blog.junebuy.com;
access_log /var/www/logs/blog.junebuy.com.log main;

location / {
root /var/www/zcping-blog;
index index.php index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/blog.junebuy.com/$fastcgi_script_name;
include fastcgi_params;
}

location ~ /.ht {
deny all;
}
}

3. 打开 /etc/nginix.conf 或者是/etc/nginx/nginx.conf文件,在相应位置加入 include 把以上2个文件包含进来。
# 包含所有的虚拟主机的配置文件
include /etc/nginx/vhosts/*;

4. 报file not found 是怎么回事?如果添加完成以后出现file not found,我这里出现的问题是这个路径写错了,写的是一个不存在的路径,修改到正确即可:

fastcgi_param SCRIPT_FILENAME /xxx/$fastcgi_script_name;

 

 

lnmp 1.2之后通过简单命令行配置,非常方便:

[root@xinyang siqi]# lnmp vhost add
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
Please enter domain(example: www.lnmp.org): zxmr.junebuy.com
Your domain: zxmr.junebuy.com
Enter more domain name(example: lnmp.org *.lnmp.org):
Please enter the directory for the domain: zxmr.junebuy.com
Default directory: /home/wwwroot/zxmr.junebuy.com: /home/wwwroot/siqi/zxmr.junebuy.com
Virtual Host Directory: /home/wwwroot/siqi/zxmr.junebuy.com
Allow Rewrite rule? (y/n)
You choose rewrite: none
Allow access log? (y/n)
Disable access log.
Create database and MySQL user with same name (y/n) n
Add SSL Certificate (y/n)

Press any key to start create virtul host...

Create Virtul Host directory......
set permissions of Virtual Host directory......
You select the exist rewrite rule:/usr/local/nginx/conf/none.conf
Test Nginx configure file......
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......
Gracefully shutting down php-fpm . done
Starting php-fpm done
================================================
Virtualhost infomation:
Your domain: zxmr.junebuy.com
Home Directory: /home/wwwroot/siqi/zxmr.junebuy.com
Rewrite: none
Enable log: yes
Create database: no
Create ftp account: no
================================================