nginx多域名的配置方法

方法一:多个.conf方法

       1. 到/usr/local/nginx/ 新建一个目录 vhosts  并创建两个conf文件,如:wodejj.com.conf ,xiaobing.com.conf。

           内容如下:

           

 log_format xiaobing_main '$remote_addr - $remote_user [$time_local] "$request" '
                                  '$status $body_bytes_sent "$http_referer" '
                                  '"$http_user_agent" "$http_x_forwarded_for"';
 #注意此处要放在server段的前面 不然会有“nginx: [emerg] duplicate "log_format" name "access" in /*****/conf/*****.conf:9” 的错误。


server { listen
80; server_name www.xiaobing.com;#其它的conf文件更改此位置的域名 就可以实现多域名的配置了, #charset koi8-r; access_log logs/www.xiaobing.com.log xiaobing_main; location / { root /data/xiao_bing; # 此处 是网页文件的存放目录要改到实际位置
index index.php index.html index.htm; } error_page
404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /data/xiaobing; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/xiao_bing/$fastcgi_script_name;#此处要改的,
include fastcgi_params; } # deny access to .htaccess files,
if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }


2. 将以上创建 的多个域名配置文件 conf ,包含到/usr/local/nginx/conf/nginx.conf 的配置文件中

    方法及内容是:
     #include all hosts file;
     include /usr/local/nginx/vhosts/*;

3. 重启nginx  

   /usr/local/nginx/sbin/nginx -s reload

posted @ 2014-05-20 17:13  北斗极星  阅读(752)  评论(0编辑  收藏  举报