node.js - nginx为nodeJS配置静态资源SeaJS-combo
PHPz
PHPz 2017-04-17 12:00:45
0
2
655

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

正常没问题。

PHPz
PHPz

学习是最好的投资!

Antworte allen(2)
巴扎黑

直接

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

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

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

    }
}
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!