nginx服務器多虛擬主機配置

注:本詳解以D:\nginx-1.6.0此目錄爲例

1. 修改D:\nginx-1.6.0\conf裏的nginx.conf文件。

#user  nobody;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  2048;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
     
	include vhost/*.conf; #加載vhost目錄下的虛擬主機配置文件
}


 

2. 在D:\nginx-1.6.0\conf目錄下新建vhost文件夾,作爲多虛擬主機配置文件目錄。

3. 在D:\nginx-1.6.0\logs目錄下新建html、kcloud、web文件夾,作爲多虛擬主機日誌目錄

4. 複製htmlConf.conf、kcloudConf.conf、webConf.conf到D:\nginx-1.6.0\conf\vhost目錄下。

htmlConf.conf爲宣傳網站虛擬主機的配置,以下是詳細說明:

 

server {
	listen 80;
	server_name aaa.com;
	error_page  404  /404.html;
	error_log	logs/html/error.log;
	location /{ 
		root html; 
		access_log off; 
		index index.html index.htm; 
		autoindex on;
		expires 5d;
		break; 
	}
} 

 

 

webConf.conf爲web網站虛擬主機的配置,以下是詳細說明:

 

upstream SMELP {
	    server 182.254.244.33:8080;
    }
server {
	listen 80;
	server_name bbb.aaa.com;
	error_page  404  /404.html;
	error_log	logs/web/error.log;
	location /{
		proxy_pass http://SMELP;
	     	proxy_set_header        Host           bbb.aaa.com;
            	proxy_set_header        X-Real-IP       $remote_addr;
            	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
	     	client_max_body_size    1000m;
	     	client_body_buffer_size 128k;  #緩衝區代理緩衝用戶端請求的最大字節數,
            	proxy_connect_timeout 90;  #nginx跟後端服務器連接超時時間(代理連接超時)
            	proxy_send_timeout 90;        #後端服務器數據回傳時間(代理髮送超時)
            	proxy_read_timeout 90;         #連接成功後,後端服務器響應時間(代理接收超時)
		keepalive_timeout 0; 
           	proxy_http_version 1.1;
           	tcp_nodelay on;
           	proxy_set_header Connection "";
			if ( $request_uri ~* /ws/* ) {
                			return   403;
            	}

	}
} 

 

 

kcloudConf.conf爲知識庫虛擬主機的配置,以下是詳細說明:

 

upstream kcloud {
	   server 182.254.244.33:9090;
    }
server {
	listen 80;
	server_name ccc.aaa.com;
	error_page  404  /404.html;
	error_log	logs/kcloud/error.log;
	location /kcloud{
		proxy_pass http://kcloud;
	     	proxy_set_header        Host           ccc.aaa.com;
           	proxy_set_header        X-Real-IP       $remote_addr;
           	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
	     	client_max_body_size    1000m;
	     	client_body_buffer_size 128k;  #緩衝區代理緩衝用戶端請求的最大字節數,
           	proxy_connect_timeout 90;  #nginx跟後端服務器連接超時時間(代理連接超時)
            	proxy_send_timeout 90;        #後端服務器數據回傳時間(代理髮送超時)
            	proxy_read_timeout 90;         #連接成功後,後端服務器響應時間(代理接收超時)
		keepalive_timeout 0; 
           	proxy_http_version 1.1;
           	tcp_nodelay on;
           	proxy_set_header Connection "";
		
	}
} 

 

5. 將靜態html宣傳頁網站文件複製到D:\nginx-1.6.0\html目錄下。

6. 啓動相應的web服務和知識庫服務,其中web服務以ROOT項目名部署。

7. cmd定位到D:\nginx-1.6.0,輸入start nginx。啓動nginx服務即可。

附資源下載地址:http://download.csdn.net/detail/qq_31204765/9572095

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章