nginx多虚拟主机配置

  1. 1.nginx.conf内容如下:  
  2. 程序代码  
  3. worker_processes 1;  
  4.   
  5. error_log /host/nginx/logs/error.log crit;  
  6.   
  7. pid /host/nginx/logs/nginx.pid;  
  8.   
  9. events {  
  10. worker_connections 64;  
  11. }  
  12.   
  13. http {  
  14. include /host/nginx/conf/mime.types;  
  15. default_type application/octet-stream;  
  16.   
  17. #charset gb2312;  
  18.   
  19. server_names_hash_bucket_size 128;  
  20. client_header_buffer_size 32k;  
  21. large_client_header_buffers 4 32k;  
  22.   
  23. keepalive_timeout 60;  
  24.   
  25. fastcgi_connect_timeout 300;  
  26. fastcgi_send_timeout 300;  
  27. fastcgi_read_timeout 300;  
  28. fastcgi_buffer_size 128k;  
  29. fastcgi_buffers 4 128k;  
  30. fastcgi_busy_buffers_size 128k;  
  31. fastcgi_temp_file_write_size 128k;  
  32. client_body_temp_path /host/nginx/client_body_temp;  
  33. proxy_temp_path /host/nginx/proxy_temp;  
  34. fastcgi_temp_path /host/nginx/fastcgi_temp;  
  35.   
  36. gzip on;  
  37. gzip_min_length 1k;  
  38. gzip_buffers 4 16k;  
  39. gzip_http_version 1.0;  
  40. gzip_comp_level 2;  
  41. gzip_types text/plain application/x-javascript text/css application/xml;  
  42. gzip_vary on;  
  43.   
  44. client_header_timeout 3m;  
  45. client_body_timeout 3m;  
  46. send_timeout 3m;  
  47. sendfile on;  
  48. tcp_nopush on;  
  49. tcp_nodelay on;  
  50. #设定虚拟主机  
  51. include /host/nginx/conf/vhost/www_test_com.conf;  
  52. include /host/nginx/conf/vhost/www_test1_com.conf;  
  53. include /host/nginx/conf/vhost/www_test2_com.conf;  
  54. }  
  55.   
  56.   
  57.   
  58. 2.在conf目录下建立个vhost目录,在vhost目录下分别建立www_test_com.conf,www_test1_com.conf,www_test2_com.conf 3个文件  
  59.   
  60. www_test_com.conf代码如下:  
  61. 程序代码  
  62. server {  
  63. listen 202.***.***.***:80; #换成你的IP地址  
  64. client_max_body_size 100M;  
  65. server_name www.test.com; #换成你的域名  
  66. charset gb2312;  
  67. index index.html index.htm index.php;  
  68. root /host/wwwroot/test; #你的站点路径  
  69.   
  70. #打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件  
  71. autoindex on;  
  72.   
  73. if (-d $request_filename) {  
  74. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;  
  75. }  
  76.   
  77. error_page 404 /404.html;  
  78. location = /40x.html {  
  79. root /host/wwwroot/test; #你的站点路径  
  80. charset on;  
  81. }  
  82.   
  83. # redirect server error pages to the static page /50x.html  
  84. #  
  85. error_page 500 502 503 504 /50x.html;  
  86. location = /50x.html {  
  87. root /host/wwwroot/test; #你的站点路径  
  88. charset on;  
  89. }  
  90.   
  91. #将客户端的请求转交给fastcgi  
  92. location ~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ {  
  93. fastcgi_pass 127.0.0.1:9000;  
  94. include /host/nginx/conf/fastcgi_params;  
  95. }  
  96.   
  97. #网站的图片较多,更改较少,将它们在浏览器本地缓存15天  
  98. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
  99. {  
  100. expires 15d;  
  101. }  
  102.   
  103. #网站会加载很多JS、CSS,将它们在浏览器本地缓存1天  
  104. location ~ .*\.(js|css)?$  
  105. {  
  106. expires 1d;  
  107. }  
  108.   
  109. location /(WEB-INF)/ {   
  110. deny all;   
  111. }  
  112.   
  113. #设定日志格式  
  114. log_format access '$remote_addr - $remote_user [$time_local] "$request" '  
  115. '$status $body_bytes_sent "$http_referer" '  
  116. '"$http_user_agent" $http_x_forwarded_for';  
  117. #设定本虚拟主机的访问日志  
  118. access_log /host/nginx/logs/down/access.log access; #日志的路径,每个虚拟机一个,不能相同  
  119. server_name_in_redirect off;  
  120. }  
  121.   
  122.   
  123.   
  124. 3.www_test1_com.conf和www_test2_com.conf,文件和上面的基本相同,具体的日志内容如下:  
  125. www_test1_com.conf如下:  
  126. 程序代码  
  127. ..........  
  128.   
  129. #设定日志格式  
  130. log_format test1 '$remote_addr - $remote_user [$time_local] "$request" '  
  131. '$status $body_bytes_sent "$http_referer" '  
  132. '"$http_user_agent" $http_x_forwarded_for';  
  133. #设定本虚拟主机的访问日志  
  134. access_log /host/nginx/logs/test1/test1.log test1; #日志的路径,每个虚拟机一个,不能相同  
  135. server_name_in_redirect off;  
  136. }  
  137.   
  138.   
  139.   
  140. www_test2_com.conf如下:  
  141. 程序代码  
  142. ..........  
  143.   
  144. #设定日志格式  
  145. log_format test2 '$remote_addr - $remote_user [$time_local] "$request" '  
  146. '$status $body_bytes_sent "$http_referer" '  
  147. '"$http_user_agent" $http_x_forwarded_for';  
  148. #设定本虚拟主机的访问日志  
  149. access_log /host/nginx/logs/test2/test2.log test2; #日志的路径,每个虚拟机一个,不能相同  
  150. server_name_in_redirect off;  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值