NGINX配置

本配置解决两个问题

  1. 多域名同端口映射不同项目
  2. root和alias的区别

server_name可解决多域名同端口的问题。其实一般情况用不到,只是我们的项目是老项目,旧地址已经被很多地方引用了,不能改原来的。所以要在原有路径基础上新增域名。具体示例如下:

    server {
        listen       8089;
        server_name  wind.taobao.com;
        location / {
                add_header "Access-Control-Allow-Origin" *;
                root /data/apps/portal-ui/;
                if ($request_filename ~* .*\.(?:htm|html)$){
                        add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
                }
                index /index.html;
                try_files $uri $uri/ /index.html;
        }
        location /portal-server {
                proxy_pass http://10.10.10.10:9090/portal-server;
        }
    }
    server {
        listen       8089;
        server_name  wind.taobao.sit test.taobao.net;
        client_max_body_size 100M;
        root    /data/apps/sulphur;
        index  index1.html index1.htm;
        add_header Access-Control-Allow-Origin *;
        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})"){
                set $year $1;
                set $month $2;
                set $day $3;
                set $hour $4;
                set $minutes $5;
                set $seconds $6;
        }

        access_log  logs/$year-$month-$day.host.access.log;

        error_log logs/$year-$month-$day.error.log;
        location /portal/ {
            alias /data/apps/portal-ui/;
            index  index.html index.htm;
        }
        location /online {
            root /data/apps;
            index  index.html index.htm;
        }

直接访问http://wind.taobao.com

或者访问http://wind.taobao.sit/portal

或者访问http://test.taobao.net/portal 

都是同一个项目

而访问http://wind.taobao.sit 就是另一个项目。


root

        对于不需要路径的项目直接 在后面加路径就可以。结尾有没有"/"都行。例如

        location / {
                root /data/apps/portal-ui/;               
                index /index.html;
                try_files $uri $uri/ /index.html;
        }

        对于需要路径的项目。直接在后面加路径之前的地址。例如

        location /portal {
            root /data/apps;
            index  index.html index.htm;
        }

实际项目路径在 /data/apps/portal/ 里 

假如项目在/data/apps/portal-ui-2021-0909里面。而访问路径还是portal。就需要alias

alias 不论有没有路径,都需要写全路径。而且,路径要以“/”结尾。例如

        location /bpm-portal/ {
            alias /data/apps/bpm-portal-ui/;
            index  index.html index.htm;
        }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值