nginx 로 프록시 서버 구축 후 웹 애플리케이션에서 path 설정 문제.
조회수 2795회
안녕하세요. node.js 웹 애플리케이션을 공부 및 개발 중입니다.
EC2 서버를 한 10번은 갈아 엎어서 드디어 프록시 서버를 구축하였습니다.
nginx -> node.js
그리고 로컬에서 개발 중이던 웹 애플리케이션을 서버에 적용하였더니 경로가 완전 씹어 먹히네요.
파일 구조는
nodejs_app
- config
- mysql
- node_modules
- public
- stylesheets
- index.css
- routes
- views
- index.ejs
- app.js
- package.json
- README.md
이고, css 파일 index.css 을 불러오기 위해
app.js 에서
app.use(express.static(path.join(__dirname, 'public')));
하고
index.ejs 파일에서
<link rel='stylesheet' href='./stylesheets/index.css' />
로 하였더니, 컴파일된 링크가 http://example.com/stylesheets/index.css 로 되었습니다.
그래서 혹시나 해서, node.js 웹 포트가 8080로 되어 있어 http://example.com:8080/stylesheets/index.css 로 접속하였더니 해당 css 파일이 보입니다.
nginx로 프록시 된 node.js 에서 path를 어떻게 잡아줘야 할까요?
nginx 에서 conf 설정은 다음과 같습니다.
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
proxy_pass http://example.com:8080;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
ps. 뿐만 아니라 index.ejs 에서 다른 메뉴로 이동하는 링크 모두 path 가 깨졌습니다. 결국 프록시 경로 문제인데 어떻게 해결해야할지 엄두가 안납니다. ㅠㅠ
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력