Linux上Nginx如何添加多个虚拟主机配置

配置虚拟机端口
1 添加iptables端口 vi /etc/sysconfig/iptables 找到 -A INPUT -s 172.16.0.0/16 这一行,加入新加的端口
2 重启iptables  /etc/init.d/iptables restart
3 添加rewrite配置文件 在/usr/local/etc/openresty/sites-available 下创建文件
如 http-appadmin.conf 
内容如下
server
{
    listen 8089;
    index index.html index.php;
    root /var/www/cloudplatform/appstore/public/app/;
    location / {
        index index.html index.php;
    }
    location ~ \.php$ {
        #auth_request /auth;
        fastcgi_pass   php-fcgi;
        include        fastcgi.conf;
    }


}
4建立软连接到sites-enable里去
ln -s /usr/local/etc/openresty/sites-available/http-appadmin.conf /usr/local/etc/openresty/sites-enable/http-appadmin.conf

5重启nginx



rewrite规则:

server {
        listen       8088;


        charset utf-8;


        gzip        on;
        gzip_types  text/plain application/json;
        gzip_proxied    no_etag;


        error_log   /var/log/openresty/api.appstore.smartisan.cn_error.log;
        access_log  /var/log/openresty/api.appstore.smartisan.cn_access.log;


        root    /var/www/cloudplatform/appstore/public/api;


        location / {
            rewrite /category/list.json /appstore.php?c=category last;
           
            if ($request_method = DELETE) {
                rewrite /collect/([1-9][0-9]*).json /appstore.php?c=delCollect&aid=$1 last;    #删除心愿单
                return 403;
            }
            return 404;
        }
        #排行榜
        location /top {
            rewrite /top/size/([1-9][0-9]*)/page/([1-9][0-9]*)/list.json /appstore.php?c=top&size=$1&page=$2 last;
            rewrite /top/size/([1-9][0-9]*)/list.json /appstore.php?c=top&size=$1 last;
        }
        #通过专题ID获取推荐列表
        location ~*/([1-9][0-9]*)/topic{
            rewrite /([1-9][0-9]*)/topic/size/([1-9][0-9]*)/page/([1-9][0-9]*)/list.json /appstore.php?c=getAppByTopic&tid=$1&size=$2&page=$3 last;
            rewrite /([1-9][0-9]*)/topic/size/([1-9][0-9]*)/list.json /appstore.php?c=getAppByTopic&tid=$1&size=$2 last;
        }
location ~*\.ico$ {
            return 404;
        }
        location = /auth {
            internal;


            return 401;
        }


        location ~ \.php$ {
            #auth_request /auth;


            fastcgi_pass   php-fcgi;
            include        fastcgi.conf;
        }


        location ~ /\.ht {
            deny  all;
        }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值