2017-12-28 3 views
0

내 Express 앱은 브라우저에서 정적 파일을로드 할 수 없지만 말린 상태로 작동합니다. 나는 웹 서버로 nginx를 사용한다. 응용 프로그램은 잘 작동하지만 정적 파일이 없습니다. 여기서 내가 뭘 잘못하고 있니?Express/Nginx에서 정적 파일을로드 할 수 없습니다.

http://127.0.0.1:1337/data/pic.png 

그러나 브라우저가되지 않습니다 : :

App.js

... 

App.use(cors()) 
App.use("/data", express.static(__dirname + '/data')); 

App.use('/api', require('./routes/api')) 

App.listen(1337) 

의 nginx

server 
{ 
     listen x.x.x.x:80; 
     server_name example.com www.example.com ; 

     location /api { 

       proxy_pass http://x.x.x.x:1337; 

       ... 
     } 

    location/{ 
       return 301 https://$server_name$request_uri; 
     } 

} 

server 
{ 
     listen x.x.x.x:443 ssl; 
     server_name example.com www.example.com ; 
    root /path/to/public_html; 
     index index.php index.html index.htm; 
     ssl on; 
     location /api { 
       add_header X-Cache "HIT from Backend"; 

       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_pass http://x.x.x.x:1337; 

       ... 
     } 
} 

컬 괜찮

http://example.com/api/data/pic.png 
,

라우터 :

App.use('/api', require('./routes/api')) 
+1

http://x.x.x.x:1337/data/pic.png에 리디렉션이 Nginx에의 설정을 시도 내 라우터는 @Farnabaz, 당신 브라우저 주소 – Farnabaz

+0

에/api''제거 – user1788781

답변

1

당신이 브라우저에서 잘못된 주소를 요청 http://example.com/api/data/pic.png

location /api { 
    rewrite /api(.*) /$1 break; 
    proxy_pass http://x.x.x.x:1337; 

    ... 
} 
+0

불행히도 작동하지 않습니다. – user1788781

+0

'http://example.com/api/data'에 대한 요청의 요청/응답 헤더는 무엇입니까? (예 : '/ api', require ('./ routes/api'))/pic.png'? – Khang

관련 문제