FAQ

Page Discussion Edit History

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;
: }
: }