layout: post
title: "Nginx虛擬主機(jī)配置"
date: 2016-05-16 23:36:00 +0800
comments: true
categories: [nginx]
今天閑下來(lái)決定把騰訊云服務(wù)器上的網(wǎng)站弄成虛擬主機(jī)。畢竟通過(guò) /xx/xx訪問(wèn)也不成樣子 0.0
增加虛擬主機(jī)
- 進(jìn)入
/etc/nginx/conf.d
目錄, 創(chuàng)建虛擬主機(jī)配置文件 demo.neoease.com.conf ({域名}.conf) 這個(gè)目錄每個(gè)人都是不同的豌蟋,進(jìn)到你的配置目錄就好了 - 打開(kāi)配置文件, 添加服務(wù)如下:
<pre class="prettyprint linenums">
server {
listen 80;
server_name demo.neoease.com;
index index.html index.htm index.php;
root /var/www/demo_neoease_com;
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';
access_log /var/log/demo.neoease.com.log demo.neoease.com;
}
</pre>
- 打開(kāi) Nginx 配置文件 /usr/local/nginx/conf/nginx.conf, 在 http 范圍引入虛擬主機(jī)配置文件如下:
<pre class="prettyprint">
include vhost/*.conf;
這個(gè)一般來(lái)說(shuō)都是有的柳恐。
</pre>
讓 Nginx 虛擬主機(jī)支持 PHP
在前面第 2 步的虛擬主機(jī)服務(wù)對(duì)應(yīng)的目錄加入對(duì) PHP 的支持, 這里使用的是 FastCGI, 修改如下.
<pre class="prettyprint linenums">
server {
listen 80;
server_name class.ewanreton.cn;
index index.html index.htm index.php;
root /usr/share/nginx/html/class;
location ~ \.php$ {
root /usr/share/nginx/html/class;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
log_format class.ewanreton.cn '$remote_addr - $remote_user [$time_local] $request'
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /var/log/class.ewanreton.cn.log class.ewanreton.cn;
}
這個(gè)是我騰訊云服務(wù)器上的版本伟墙。中間配置PHP支持與原博文有所不一樣。
</pre>
重啟 Nginx 服務(wù), 執(zhí)行以下語(yǔ)句.
<pre class="prettyprint linenums">
service nginx restart
</pre>