node.js - nginx为nodeJS配置静态资源SeaJS-combo

 zy7ume 发布于 2022-11-04 15:25

想用nginx做反向代理,代理上游为nodeJS程序,如果想要配置静态资源combo服务应该要怎样

配置如下:

情况一
配置:

    server {
        listen       5555;
        server_name  172.16.42.97;

        location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
        {
            root /usr/local/nginx/html;
            index  index.html;
            concat on;                      
            concat_max_files 20;            
            concat_unique on;               
            concat_types "application/javascript" "text/css";
        }
        location /
        {
            proxy_pass http://172.16.42.97:4000/;
        }
    }

报错502。

情况二
配置:

    server {
        listen       5555;
        server_name  172.16.42.97;

        location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
        {
            root /usr/local/nginx/html;
            index  index.html;
            concat on;                      
            concat_max_files 20;            
            concat_unique on;               
            concat_types "application/javascript" "text/css";
        }
    }

报错Uncaught SyntaxError: Unexpected token <
combo合成失败

情况三
配置:

server {
        listen       5555;
        server_name  172.16.42.97;

        location /
        {
            root /usr/local/nginx/html;
            index  index.html;
            concat on;                      
            concat_max_files 20;           
            concat_unique on;              
            concat_types "application/javascript" "text/css"; 
        }

正常没问题。

2 个回答
  • server {
        listen 80;
        server_name localhost;
        access_log /www/logs/www.log;
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            root /www/html/public;
            expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
            root /www/html/public;
             expires 1h;
        }
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host  $http_host;
            #proxy_set_header X-Nginx-Proxy true;
            proxy_set_header Connection "";
            proxy_pass      http://localhost:3002;
    
        }
    }
    2022-11-08 00:28 回答
  • 直接

    location / {
        proxy_pass http://172.16.42.97:4000/;
    }
    

    把非静态资源请求全部扔过去就行了,不用什么表达式。

    2022-11-08 00:38 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有