在ubuntu利用nginx反响代理在一个端口下配置多个站点

在ubuntu利用nginx反响代理在一个端口下配置多个站点

在一个服务器下,暂时没有域名,多域名很容易这里不做过多的说明。

一台服务器的 ip如下:192.168.1.101 默认的niginx 80端口。项目目录在/var/www/html 下 我们新建另一个项目目录 在/var/www/wecaht
若果我们访问192.168.1.101/wechat 需要配置如下:

我还是需要另一个端口 比如8001 在/etc/nginx/sites-available 下新建配置文件 wechat 
    listen 8001;
    server_name wechat.com;

    root /var/www/wechat;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;
    location ~* \.(eot|otf|ttf|woff)$ {
        add_header Access-Control-Allow-Origin *;
    }
    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.php?$args;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

ln -s /etc/nginx /sites-available /etc/nginx/sites-enable/wechat
创建软连接
保存推出 service nginx restart
访问192.168.1.101:8001 我们将访问 wechat 目录的php项目
现在我们在 默认配置文件 /etc/nginx /sites-available/default 增加反向代理
location /wechat/ {
proxy_pass http://192.168.1.101:8001;
}

然后重启 nginx 服务器

访问 http://192.168.1.101/wechat 就ok了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值