Nginx虛擬主機VirtualHost配置

jefferyjob發表於2016-03-28

原文地址: http://www.neoease.com/nginx-virtual-host/

增加 Nginx 虛擬主機


1. 進入 /usr/local/nginx/conf/目錄, 建立虛擬主機配置檔案 demo.neoease.com.conf ({域名}.conf).

2. 開啟配置檔案, 新增服務如下:

log_format demo.neoease.com `$remote_addr - $remote_user [$time_local] $request`
`$status $body_bytes_sent $http_referer `
`$http_user_agent $http_x_forwarded_for`;
server {
	listen       80;
	server_name demo.neoease.com;
	index index.html index.htm index.php;
	root  /var/www/demo_neoease_com;	
	#access_log  /var/log/demo.neoease.com.log demo.neoease.com;
}

3. 開啟 Nginx 配置檔案 /usr/local/nginx/conf/nginx.conf, 在 http 範圍引入虛擬主機配置檔案如下:

include demo.neoease.com.conf;

4. 重啟 Nginx 服務, 執行以下語句.

service nginx restart

讓 Nginx 虛擬主機支援 PHP
在前面第 2 步的虛擬主機服務對應的目錄加入對 PHP 的支援, 這裡使用的是 FastCGI, 修改如下.

log_format demo.neoease.com `$remote_addr - $remote_user [$time_local] $request`
`$status $body_bytes_sent $http_referer `
`$http_user_agent $http_x_forwarded_for`;
server {
	listen       80;
	server_name demo.neoease.com;
	index index.html index.htm index.php;
	root  /var/www/demo_neoease_com;
	location ~ .*.(php|php5)?$ {
		fastcgi_pass unix:/tmp/php-cgi.sock;
		fastcgi_index index.php;
		include fcgi.conf;
	}
	#access_log  /var/log/demo.neoease.com.log demo.neoease.com;
}


相關文章