### 虛擬主機
### 兩個虛擬主機(純靜態-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
這是一個添加子域名(或是當DNS已指向服務器時添加一個新域名)的簡單方法。需要注意的是,我已經將FCGI配置進該文件了。如果你只想使服務器為靜態文件服務,可以直接將FCGI配置信息注釋掉,然后將默認主頁文件變成index.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
: # 如果需要,你可以為不同的FCGI進程設置不同的服務信息
: 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;
: }
: }
~~~
- 主要文檔
- Nginx功能概述
- 為什么選擇Nginx
- Nginx安裝
- 運行和控制Nginx
- 配置符號參考
- 優化 Nginx
- 常見問題(FAQ)
- 調試 nginx
- 核心模塊
- Nginx主模塊
- Nginx事件模塊
- 基本模塊
- http核心模塊
- HttpIndex模塊
- HttpAccess模塊
- HttpAuthBasic模塊
- HttpAutoindex模塊
- Browser模塊
- Charset模塊
- HttpEmptyGif模塊
- HttpFcgi模塊
- Geo模塊
- HttpGzip模塊
- HttpHeaders模塊
- HttpIndex模塊
- HttpReferer模塊
- HttpLimit zone
- HttpLimitReqest模塊
- HttpLog模塊
- map
- Memcached
- HttpProxy模塊
- HttpRewrite模塊
- HttpSSI模塊
- HttpUserId
- 其他模塊
- Addition模塊
- EmbeddedPerl
- flv
- HttpGzipStatic
- RandomIndex
- HttpGeoIP
- HttpRealIp
- HttpSSL
- StubStatus模塊
- HttpSubstitution
- HttpDav模塊
- GooglePerftools
- HttpXSLT
- HttpSecureLink
- HttpImageFilter
- mail模塊
- MailCore
- MailAuth
- MailProxy
- MailSSL
- 安裝
- nginx在windows上的安裝
- nginx在freebsd上的安裝
- nginx在ubuntu上的安裝
- nginx在fedora上的安裝
- nginx php-fpm安裝配置
- 配置示例和方法
- 完整例子
- 完整例子2
- 虛擬主機
- 負載均衡
- nginx防盜鏈
- HWLoadbalancerCheckErrors