ChsFullExample
涓や釜铏氭嫙涓绘満(绾潤鎬-html 鏀寔) - Two Virtual Hosts, Serving Static Files
http { : server { : listen 80; : server_name www.domain1.com; : access_log logs/domain1.access.log main; : location / { : index index.html; : root /var/www/domain1.com/htdocs; : } : } : server { : listen 80; : server_name www.domain2.com; : access_log logs/domain2.access.log main; : location / { : index index.html; : root /var/www/domain2.com/htdocs; : } : } }
铏氭嫙涓绘満鏍囧噯閰嶇疆(绠鍖) - A Default Catchall Virtual Host
http { : server { : listen 80 default; : server_name _ *; : access_log logs/default.access.log main; : location / { : index index.html; : root /var/www/default/htdocs; : } : } }
鍦ㄧ埗鏂囦欢澶逛腑寤虹珛瀛愭枃浠跺す浠ユ寚鍚戝瓙鍩熷悕 - Wildcard Subdomains in a Parent Folder
杩欐槸涓涓坊鍔犲瓙鍩熷悕(鎴栨槸褰揇NS宸叉寚鍚戞湇鍔″櫒鏃舵坊鍔犱竴涓柊鍩熷悕)鐨勭畝鍗曟柟娉曘傞渶瑕佹敞鎰忕殑鏄紝鎴戝凡缁忓皢FCGI閰嶇疆杩涜鏂囦欢浜嗐傚鏋滀綘鍙兂浣挎湇鍔″櫒涓洪潤鎬佹枃浠舵湇鍔★紝鍙互鐩存帴灏咶CGI閰嶇疆淇℃伅娉ㄩ噴鎺夛紝鐒跺悗灏嗛粯璁や富椤垫枃浠跺彉鎴恑ndex.html銆
杩欎釜绠鍗曠殑鏂规硶姣旇捣涓烘瘡涓涓煙鍚嶅缓绔嬩竴涓 vhost.conf 閰嶇疆鏂囦欢鏉ヨ锛屽彧闇瑕佸湪鐜版湁鐨勯厤缃枃浠朵腑澧炲姞濡備笅鍐呭锛
This is just a really easy way to keep adding new subdomains, or to add new domains automatically when DNS records are pointed at the server. Note that I have included FCGI here as well. If you want to just serve static files, strip out the FCGI config and change the default document to index.html. Rather than creating a new vhost.conf file for every domain, just create one of these:
server { : # Replace this port with the right one for your requirements : # 鏍规嵁浣犵殑闇姹傛敼鍙樻绔彛 : listen 80; #could also be 1.2.3.4:80 涔熷彲浠ユ槸1.2.3.4:80鐨勫舰寮 : # Multiple hostnames seperated by spaces. Replace these as well. : # 澶氫釜涓绘満鍚嶅彲浠ョ敤绌烘牸闅斿紑锛屽綋鐒惰繖涓俊鎭篃鏄渶瑕佹寜鐓т綘鐨勯渶姹傝屾敼鍙樼殑銆 : server_name star.yourdomain.com *.yourdomain.com www.*.yourdomain.com; : #Alternately: _ * : #鎴栬呭彲浠ヤ娇鐢細_ * (鍏蜂綋鍐呭鍙傝鏈淮鍩哄叾浠栭〉闈) : root /PATH/TO/WEBROOT/$host; : error_page 404 http://yourdomain.com/errors/404.html; : access_log logs/star.yourdomain.com.access.log; : location / { : root /PATH/TO/WEBROOT/$host/; : index index.php; : } : # serve static files directly : # 鐩存帴鏀寔闈欐佹枃浠 (浠庨厤缃笂鐪嬫潵涓嶆槸鐩存帴鏀寔鍟) : location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ { : access_log off; : expires 30d; : } : location ~ .php$ { : # By all means use a different server for the fcgi processes if you need to : # 濡傛灉闇瑕侊紝浣犲彲浠ヤ负涓嶅悓鐨凢CGI杩涚▼璁剧疆涓嶅悓鐨勬湇鍔′俊鎭 : fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE; : fastcgi_index index.php; : fastcgi_param SCRIPT_FILENAME /PATH/TO/WEBROOT/$host/$fastcgi_script_name; : fastcgi_param QUERY_STRING $query_string; : fastcgi_param REQUEST_METHOD $request_method; : fastcgi_param CONTENT_TYPE $content_type; : fastcgi_param CONTENT_LENGTH $content_length; : fastcgi_intercept_errors on; : } : location ~ /\.ht { : deny all; : } : }