服務(wù)項(xiàng)目:網(wǎng)站建設(shè)、仿站、程序開(kāi)發(fā)、APP開(kāi)發(fā)設(shè)計(jì)、移動(dòng)網(wǎng)站開(kāi)發(fā)設(shè)計(jì)、企業(yè)網(wǎng)站設(shè)計(jì)、電子商務(wù)網(wǎng)站開(kāi)發(fā)、網(wǎng)站維護(hù)、網(wǎng)站推廣、UX/UI 、HTML5、CSS3、JS / Jquery ...
四川???萍加邢薰?></a></div>
                    <div   id=四川浚??萍加邢薰? title=
四川???萍加邢薰?(開(kāi)發(fā)設(shè)計(jì)官網(wǎng))TEL : 15308000360 / QQ : 38585404

您的位置:首頁(yè) > 技術(shù)經(jīng)驗(yàn) > 服務(wù)器 > 正文

NGINX多虛擬主機(jī)配置設(shè)置
技術(shù)支持服務(wù)電話:15308000360 【7x24提供運(yùn)維服務(wù),解決各類系統(tǒng)/軟硬件疑難技術(shù)問(wèn)題】

1.nginx.conf 內(nèi)容如下:

worker_processes 1; 
error_log /host/nginx/logs/error.log crit; 

pid /host/nginx/logs/nginx.pid; 

events { 
worker_connections 64; 
} 

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

#charset gb2312; 

server_names_hash_bucket_size 128; 
client_header_buffer_size 32k; 
large_client_header_buffers 4 32k; 

keepalive_timeout 60; 

fastcgi_connect_timeout 300; 
fastcgi_send_timeout 300; 
fastcgi_read_timeout 300; 
fastcgi_buffer_size 128k; 
fastcgi_buffers 4 128k; 
fastcgi_busy_buffers_size 128k; 
fastcgi_temp_file_write_size 128k; 
client_body_temp_path /host/nginx/client_body_temp; 
proxy_temp_path /host/nginx/proxy_temp; 
fastcgi_temp_path /host/nginx/fastcgi_temp; 

gzip on; 
gzip_min_length 1k; 
gzip_buffers 4 16k; 
gzip_http_version 1.0; 
gzip_comp_level 2; 
gzip_types text/plain application/x-javascript text/css application/xml; 
gzip_vary on; 

client_header_timeout 3m; 
client_body_timeout 3m; 
send_timeout 3m; 
sendfile on; 
tcp_nopush on; 
tcp_nodelay on; 
#設(shè)定虛擬主機(jī) 
include /host/nginx/conf/vhost/www_test_com.conf; 
include /host/nginx/conf/vhost/www_test1_com.conf; 
include /host/nginx/conf/vhost/www_test2_com.conf; 
} 
2.在conf目錄下建立個(gè)vhost目錄,在vhost目錄下分別建立 www_test_com.conf,www_test1_com.conf,www_test2_com.conf 3個(gè)文件     
www_test_com.conf 如下:
server {
listen 202.***.***.***:80; #換成你的IP地址 
client_max_body_size 100M; 
server_name www.test.com; #換成你的域名 
charset gb2312; 
index index.html index.htm index.php; 
root /host/wwwroot/test; #你的站點(diǎn)路徑 

#打開(kāi)目錄瀏覽,這樣當(dāng)沒(méi)有找到index文件,就也已瀏覽目錄中的文件 
autoindex on; 

if (-d $request_filename) { 
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; 
} 

error_page 404 /404.html; 
location = /40x.html { 
root /host/wwwroot/test; #你的站點(diǎn)路徑 
charset on; 
} 

# redirect server error pages to the static page /50x.html 
# 
error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
root /host/wwwroot/test; #你的站點(diǎn)路徑 
charset on; 
} 


#將客戶端的請(qǐng)求轉(zhuǎn)交給fastcgi 
location ~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ { 
fastcgi_pass 127.0.0.1:9000; 
include /host/nginx/conf/fastcgi_params; 
} 


#網(wǎng)站的圖片較多,更改較少,將它們?cè)跒g覽器本地緩存15天  

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ 
{ 
expires 15d; 
} 

#網(wǎng)站會(huì)加載很多JS、CSS,將它們?cè)跒g覽器本地緩存1天 
location ~ .*\.(js|css)?$ 
{ 
expires 1d; 
} 

location /(WEB-INF)/ { 
deny all; 
} 

#設(shè)定日志格式

log_format access '$remote_addr - $remote_user [$time_local] "$request" ' 
'$status $body_bytes_sent "$http_referer" ' 
'"$http_user_agent" $http_x_forwarded_for'; 

#設(shè)定本虛擬主機(jī)的訪問(wèn)日志 
access_log /host/nginx/logs/down/access.log access; #日志的路徑,每個(gè)虛擬機(jī)一個(gè),不能相同 
server_name_in_redirect off; 
} 

3.www_test1_com.conf和www_test2_com.conf,文件和上面的基本相同,具體的日志內(nèi)容如下: www_test1_com.conf 如下:
#設(shè)定日志格式
log_format test1 '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#設(shè)定本虛擬主機(jī)的訪問(wèn)日志
access_log /host/nginx/logs/test1/test1.log test1; #日志的路徑,每個(gè)虛擬機(jī)一個(gè),不能相同
server_name_in_redirect off;
}
www_test2_com.conf 如下:
#設(shè)定日志格式
log_format test2 '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#設(shè)定本虛擬主機(jī)的訪問(wèn)日志
access_log /host/nginx/logs/test2/test2.log test2; #日志的路徑,每個(gè)虛擬機(jī)一個(gè),不能相同
server_name_in_redirect off;
}



上一篇:服務(wù)器高并發(fā)下的一些優(yōu)化經(jīng)驗(yàn)
下一篇:Apache開(kāi)啟GZIP壓縮設(shè)置方法

相關(guān)熱詞搜索:nginx 虛擬主機(jī) 配置方法 域名