一个nginx实现两个前端?

操作起来很简单

首先是在nginx目录下建立两个存放前端文件的地方,当然有一个是自带的html

其次就是重要的conf的配置文件

可以参考下这里的

user root;
worker_processes auto;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

  	types_hash_max_size 2048;  # 增大哈希表大小  
    types_hash_bucket_size 128;  # 调整桶大小 


    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    client_max_body_size 1024m;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    # include /etc/nginx/conf.d/*.conf;
    upstream gateway{
        server 1.1.1.1:4000;
    }
    server {
        listen 80;
        server_name 2.2.2.2.8;
        root /www/nginx/https;
        index index.html;

        keepalive_timeout 70;

        server_tokens off;
        proxy_set_header x-forwarded-for  $remote_addr;



        location / {
            root /data/bws/fileplatform/;
            index index.html;
            try_files  $uri $uri/ /index.html;
        }
        location /fileplatform/ {
            alias /data/bws/fileplatform/;
            index index.html;
            try_files  $uri $uri/ /index.html;
        }

        location /user/ {
            proxy_pass http://gateway;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
         location /lx-file/ {
            proxy_pass http://gateway/lx-file/;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /lx-auth/ {
            proxy_pass http://gateway/lx-auth/;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }


    }
  
  server {
        listen       8080;
        server_name  2.2.2.2.8;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
location /dcscloud/composite/httpfile {
            proxy_pass http://3.3.3.3:4000/dcscloud/composite/httpfile;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /dcscloud/view {
            proxy_pass http://3.3.3.3:4000/dcscloud/view;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /dcscloud/templates {
            proxy_pass http://3.3.3.3:4000/dcscloud/templates;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
         location ~ ^/dcscloud/(?!composite/httpfile|view|templates) { deny all; }
         location /dcscloud { deny all; }

        location / {
            root   html;
            index  index.html index.htm;
            try_files  $uri $uri/ /index.html;
        }
location /user {
            proxy_pass http://gateway;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /prod-api {
            proxy_pass http://2.2.2.2.8:18080;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /lx-file {
            proxy_pass http://gateway;
           proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /dcscloud/ {
            proxy_pass http://3.3.3.3:4000/dcscloud/;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
           location /fileplatform/ {
            proxy_pass http://1.1.1.1:80/fileplatform/;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }


    }
}

重点就是两个server,并且他们监听的端口不同;

过程中也遇到过很多问题,比如前端文件找不到,该怎么办,那就看打包问题吧

结合日志,以及浏览器的响应,以及接口的响应结果

希望大家没有遇到问题,稳定拿下!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值