티스토리 뷰
node.js, express를 사용하다가 local host에서 하던 작업을 서버에 올리니
css를 가져오지 못하는 문제가 발생했다.
다시 localhost에서 돌려도 너무나 잘됨
이유를 찾아보니 nginx에서 static files 처리가 되지 않아서 중간에 막히는 현상이 발생
따라서 nginx 설정을 변경해주면된다.
아래 코드에서 굵게 표시된 부분
upstream nodejs {
server localhost:3000;
}
server {
listen 8080;
server_name localhost;
root ~/workspace/test/app;
location / {
try_files $uri $uri/ @nodejs;
}
location @nodejs {
proxy_redirect off;
proxy_http_version 1.1;
proxy_pass http://nodejs;
proxy_set_header Host $host ;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
location / {
root /path/to/root/of/static/files;
try_files $uri $uri/ @apachesite;
expires max;
access_log off;
}
location @apachesite {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
원문: http://stackoverflow.com/a/29385110 / http://stackoverflow.com/a/15467555
'Programming > Web' 카테고리의 다른 글
[Node.js / deb] How to create an Ubuntu (deb) installer (for NodeJS apps) (0) | 2017.01.19 |
---|---|
Web Server / WAS (Apache / Tomcat) (0) | 2017.01.19 |
Javascript 현재시간 구하기 ( getTime, UTC, Local) (0) | 2017.01.06 |
JWT (Json Web Token) (0) | 2017.01.05 |
[Node.js/Express] interceptor 구현하기 (0) | 2017.01.04 |
댓글