検索

ホームページ  >  に質問  >  本文

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

想用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"; 
        }

正常没问题。

PHPzPHPz2872日前696

全員に返信(2)返信します

  • 巴扎黑

    巴扎黑2017-04-17 12:02:45

    直接

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

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

    返事
    0
  • PHPz

    PHPz2017-04-17 12:02:45

    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;
    
        }
    }

    返事
    0
  • キャンセル返事