nginx多域名的配置方法

本文介绍如何通过Nginx配置文件实现多个域名的独立配置,包括创建不同域名的.conf文件、设置日志格式、监听端口、指定网页文件目录等步骤,并详细展示了如何将这些配置文件包含进主配置文件以及必要的重启命令。

方法一:多个.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值