nginx配置多个项目

Neoo1984
  • 53

同一台服务器上挂两个项目,这是我当前的nginx配置:

server {
        listen 81;
        server_name localhost;    
        location / {
            root vueAdmin;
            index index.html index.htm;
        }
    }
    server {
       listen     80;
        server_name  localhost;

       # charset koi8-r;

       # access_log  logs/host.access.log  main;
        gzip on;
        gzip_min_length 1k;
        gzip_comp_level 9;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";
        root /usr/share/nginx/html;
        location / {
           root   html;
            index  index.html index.htm;
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.html?s=$1 last;
                break;
           }
        }
        
         location ^~ /jeecg-boot {
            proxy_pass              http://127.0.0.1:8089/jeecg-boot/;
            proxy_set_header        Host 127.0.0.1;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      
        }

下面的这个server是第一个项目的,没问题,现在我想再布一个项目,配置在第一个server,用的阿里云的服务器。
想请问:1. 后端说阿里云的有内网外网,代码里配置的域名应该写内网IP还是外网IP

  1. 这样配置的nginx,我输入IP+监听端口打不开,我的代码放在了html同级目录的vueAdmin文件夹下
回复
阅读 363
1 个回答
✓ 已被采纳


        server {
                listen 80;
                server_name segmentfault.com  // 此处修改
                index  index.html;

                location / {
                        #include rewrite_app.conf;
                        proxy_pass http://172.xx.x.xx:11081;  // 此处修改
                        proxy_set_header   Host             $host;
                        proxy_set_header Connection '';
                        proxy_http_version 1.1;
                        chunked_transfer_encoding off;
                        proxy_set_header   X-Real-IP        $remote_addr;
                        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

                }
                access_log  /var/log/nginx/1.log;
        }


        server {
                listen 80;
                server_name segmentfault2.com  // 此处修改
                index  index.html;

                location / {
                        #include rewrite_app.conf;
                        proxy_pass http://172.xx.x.xx:11080;  // 此处修改
                        proxy_set_header   Host             $host;
                        proxy_set_header Connection '';
                        proxy_http_version 1.1;
                        chunked_transfer_encoding off;
                        proxy_set_header   X-Real-IP        $remote_addr;
                        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

                }
                access_log  /var/log/nginx/2.log;
        }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏