nginx:vhost

nginx配置多个vhost
1.进入配置安装目录 cd /usr/local/etc/nginx/conf/
2.没有vhost文件夹 mkdir vhsot文件
3.添加多个conf文件 如:test.com.conf test1.com.conf
4.test.com.conf
server {
listen 80;
server_name test.com;
index index.html index.htm index.php;
root /Users/suncg/www/test.com;
log_format test.com '$remote_addr - $remote_user [$time_local] $request' '$status $body_bytes_sent $http_referer' '$http_user_agent $http_x_forwarded_for';
access_log /var/log/test.com.log test.com;
}

test1.com.conf
server {
listen 80;
server_name test1.com;
index index.html index.htm index.php;
root /Users/suncg/www/test1.com;
log_format test1.com '$remote_addr - $remote_user [$time_local] $request' '$status $body_bytes_sent $http_referer' '$http_user_agent $http_x_forwarded_for';
access_log /var/log/test1.com.log test1.com;
}
5.在/Users/suncg/www/ mkdir test.com 和 mkdir test1.com 以及在响应文件夹下创建 index.html 内容为1111 和 2222
6.在/usr/local/conf/nginx.conf http{}部分添加include vhost/*.conf;
如:
http
{
#include conf/mime.types;
include mime.types;
default_type application/octet-stream;
include vhost/*.conf;

keepalive_timeout 120;

tcp_nodelay on;

upstream www.samson.com {
server 127.0.0.1:8080;
# server 192.168.1.3:80;
# server 192.168.1.4:80;
# server 192.168.1.5:80;
}

server
{
listen 80;
server_name www.samson.com;

location / {
proxy_pass http://www.samson.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

log_format www_samson_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/www.log www_samson_com;
}

}

配置host
127.0.0.1 test.com
127.0.0.1 test1.com
访问test.com 显示1111 访问test1.com显示2222
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值