Nginx多虚拟主机设置

13 年 ago jony Nginx多虚拟主机设置已关闭评论

nginx.conf

  1. user  www www;
  2. worker_processes 8;
  3. error_log  /data/logs/nginx_error.log  crit;
  4. pid        /usr/local/webserver/nginx/nginx.pid;
  5. #Specifies the value for maximum file descriptors that can be opened by this process.
  6. worker_rlimit_nofile 65535;
  7. events
  8. {
  9.   use epoll;
  10.   worker_connections 65535;
  11. }
  12. http
  13. {
  14.   include       mime.types;
  15.   default_type  application/octet-stream;
  16.   #charset  gb2312;
  17.   server_names_hash_bucket_size 128;
  18.   client_header_buffer_size 32k;
  19.   large_client_header_buffers 4 32k;
  20.   client_max_body_size 8m;
  21.   sendfile on;
  22.   tcp_nopush     on;
  23.   keepalive_timeout 60;
  24.   tcp_nodelay on;
  25.   fastcgi_connect_timeout 300;
  26.   fastcgi_send_timeout 300;
  27.   fastcgi_read_timeout 300;
  28.   fastcgi_buffer_size 64k;
  29.   fastcgi_buffers 4 64k;
  30.   fastcgi_busy_buffers_size 128k;
  31.   fastcgi_temp_file_write_size 128k;
  32.   gzip on;
  33.   gzip_min_length  1k;
  34.   gzip_buffers     4 16k;
  35.   gzip_http_version 1.0;
  36.   gzip_comp_level 2;
  37.   gzip_types       text/plain application/x-javascript text/css application/xml;
  38.   gzip_vary on;
  39.   #limit_zone  crawler  $binary_remote_addr  10m;
  40.   server
  41.   {
  42.     listen 80 default;
  43.     server_name _;
  44.     index index.html index.htm index.php;
  45.     root /data/htdocs/www;
  46.     #server_name_in_redirect off;
  47.     location ~ .*\.(php|php5)?$
  48.     {
  49.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  50.       fastcgi_pass  127.0.0.1:9000;
  51.       fastcgi_index index.php;
  52.       include fcgi.conf;
  53.     }
  54.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  55.     {
  56.       expires      30d;
  57.     }
  58.     location ~ .*\.(js|css)?$
  59.     {
  60.       expires      1h;
  61.     }
  62.     }
  63.   server
  64.   {
  65.     listen       80;
  66.     server_name  www.adongstudio.com;
  67.     index index.html index.htm index.php;
  68.     root  /data/htdocs/www/adongweb;
  69.     #limit_conn   crawler  20;
  70.     location ~ .*\.(php|php5)?$
  71.     {
  72.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  73.       fastcgi_pass  127.0.0.1:9000;
  74.       fastcgi_index index.php;
  75.       include fcgi.conf;
  76.     }
  77.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  78.     {
  79.       expires      30d;
  80.     }
  81.     location ~ .*\.(js|css)?$
  82.     {
  83.       expires      1h;
  84.     }
  85.     log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
  86.               '$status $body_bytes_sent "$http_referer" '
  87.               '"$http_user_agent" $http_x_forwarded_for';
  88.     access_log  /data/logs/access.log  access;
  89.       }
  90.   server
  91.   {
  92.     listen       80;
  93.     server_name  www.longfeistudio.com;
  94.     index index.html index.htm index.php;
  95.     root  /data/htdocs/www/ImageVue;
  96.     #limit_conn   crawler  20;
  97.     location ~ .*\.(php|php5)?$
  98.     {
  99.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  100.       fastcgi_pass  127.0.0.1:9000;
  101.       fastcgi_index index.php;
  102.       include fcgi.conf;
  103.     }
  104.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  105.     {
  106.       expires      30d;
  107.     }
  108.     location ~ .*\.(js|css)?$
  109.     {
  110.       expires      1h;
  111.     }
  112.     access_log  off;
  113.       }
  114.   server
  115.   {
  116.     listen       80;
  117.     server_name  www.hongyanbike.com;
  118.     index index.html index.htm index.php;
  119.     root  /data/htdocs/www/xhui/hybike;
  120.     location ~ .*\.(php|php5)?$
  121.     {
  122.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  123.       fastcgi_pass  127.0.0.1:9000;
  124.       fastcgi_index index.php;
  125.       include fcgi.conf;
  126.     }
  127.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  128.     {
  129.       expires      30d;
  130.     }
  131.     location ~ .*\.(js|css)?$
  132.     {
  133.       expires      1h;
  134.     }
  135.     access_log  off;
  136.   }
  137. server
  138.   {
  139.     listen       80;
  140.     server_name  www.very365.com mm.very365.com very365.com;
  141.     index index.html index.htm index.php;
  142.     root  /data/htdocs/www/very365;
  143.   location /
  144.   {
  145.   rewrite ^/(.*)/product/([0-9]+)/$ /seoproduct\.php\?spell=$1&productid=$2;
  146.   rewrite ^/brand/(.*)/page/([0-9]+)/$ /seobrand\.php\?spell=$1&page=$2;
  147.   rewrite ^/brand/(.*)/$ /seobrand\.php\?spell=$1;
  148.     }
  149.     location ~ .*\.(php|php5)?$
  150.     {
  151.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  152.       fastcgi_pass  127.0.0.1:9000;
  153.       fastcgi_index index.php;
  154.       include fcgi.conf;
  155.       fastcgi_param SCRIPT_FILENAME /data/htdocs/www/very365$fastcgi_script_name;
  156.       fastcgi_param  SCRIPT_NAME  /data/htdocs/www/very365$fastcgi_script_name;
  157.     }
  158.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  159.     {
  160.       expires      30d;
  161.     }
  162.     location ~ .*\.(js|css)?$
  163.     {
  164.       expires      1h;
  165.     }
  166.     access_log  off;
  167.   }
  168. server
  169.   {
  170.     listen       80;
  171.     server_name  www.wqueen.cn wqueen.cn;
  172.      index index.html index.htm index.php;
  173.     root  /data/htdocs/www/wqueen/bbs;
  174.     location ~ .*\.(php|php5)?$
  175.     {
  176.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  177.       fastcgi_pass  127.0.0.1:9000;
  178.       fastcgi_index index.php;
  179.       include fcgi.conf;
  180.     }
  181.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  182.     {
  183.       expires      30d;
  184.     }
  185.     location ~ .*\.(js|css)?$
  186.     {
  187.       expires      1h;
  188.     }
  189.     access_log  off;
  190.     }
  191. server
  192.   {

最简单的:

  1. server 
  2. listen       80; 
  3. server_name www.web126.com;             #绑定域名 
  4. index index.htm index.html index.php;      #默认文件 
  5. root /home/www/web126.com;               #网站根目录 
  6. include location.conf;                            #调用其他规则,也可去除 
  7. server 
  8. listen       80; 
  9. server_name msn.web126.com;             #绑定域名 
  10. index index.htm index.html index.php;      #默认文件 
  11. root /home/www/msn.web126.com;        #网站根目录 
  12. include location.conf;                            #调用其他规则,也可去除