Nginx 如何添加虛擬主機_Web服務器教程

      編輯Tag賺U幣
      教程Tag:虛擬主機添加
       兩個虛擬主機,純靜態
      1. http {  
      2.   index index.html;  
      3.    
      4.   server {  
      5.     server_name www.domain1.com;  
      6.     access_log logs/domain1.access.log main;  
      7.    
      8.     root /var/www/domain1.com/htdocs;  
      9.   }  
      10.    
      11.   server {  
      12.     server_name www.domain2.com;  
      13.     access_log  logs/domain2.access.log main;  
      14.    
      15.     root /var/www/domain2.com/htdocs;  
      16.   }  

      A Default Catchall Virtual Host

       

      1. http {  
      2.   index index.html;  
      3.    
      4.   server {  
      5.     listen 80 default;  
      6.     server_name _;  
      7.     access_log logs/default.access.log main;  
      8.    
      9.     server_name_in_redirect off;  
      10.    
      11.     root  /var/www/default/htdocs;  
      12.   }  

      指定所有的二級域名

       

      1. server {  
      2.   # Replace this port with the right one for your requirements  
      3.   listen 80 [default|default_server];  #could also be 1.2.3.4:80  
      4.    
      5.   # Multiple hostnames separated by spaces.  Replace these as well.  
      6.   server_name star.yourdomain.com *.yourdomain.com; # Alternately: _  
      7.    
      8.   root /PATH/TO/WEBROOT/$host;  
      9.    
      10.   error_page 404 errors/404.html;  
      11.   access_log logs/star.yourdomain.com.access.log;  
      12.    
      13.   index index.php index.html index.htm;  
      14.    
      15.   # serve static files directly  
      16.   location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)___FCKpd___2nbsp;{  
      17.     access_log off;  
      18.     expires max;  
      19.   }  
      20.    
      21.   location ~ \.php___FCKpd___2nbsp;{  
      22.     include fastcgi_params;  
      23.     fastcgi_intercept_errors on;  
      24.     # By all means use a different server for the fcgi processes if you need to  
      25.     fastcgi_pass   127.0.0.1:YOURFCGIPORTHERE;  
      26.   }  
      27.    
      28.   location ~ /\.ht {  
      29.     deny  all;  
      30.   }  

      來源:網絡搜集//所屬分類:Web服務器教程/更新時間:2011-12-08
      相關Web服務器教程