Nginx下虚拟主机的创建

博主刚才搬迁网站,遂记录一下,话说从阿里云的香港机房搬到conoha机房之后,感觉速度慢的一逼,ping的time值在350左右,ssh的命令行都感觉卡的严重。废话不说了,简单说下过程。(以www.example.com为例) 首先创建虚拟主机网站根目录:
#mkdir /usr/share/nginx/html/www.example.com    #这是博主的网站根目录,自己结合情况随意设置
然后创建配置文件,
#mkdir /etc/nginx/vhost    #创建虚拟主机配置文件夹
#vim /etc/nginx/vhost/www.example.com.conf    #编辑www.example.com配置文件
配置文件这么写:
server {
	listen 80;
	server_name www.example.com www.example.com;
	access_log /var/log/www.example.com.log main;
	root /usr/share/nginx/html/www.example.com;
	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 /usr/share/nginx/html/www.example.com$fastcgi_script_name;
		include fastcgi_params;
	}
	location ~ /\.ht {
		deny all;
	}
	include /etc/nginx/wordpress.conf;     #Wordpress伪静态规则配置文件
}
编辑之后保存,还有最后一步要做,就是修改Nginx默认配置文件,引入www.example.com的Nginx的访问规则。
#vim /etc/nginx/nginx.conf   #不一定是这个位置,结合自己服务器情况修改
添加这么一句
include vhost/*.conf;
保存之后重启Nginx