Nginx 리버스 프록시 설정 가이드
Nginx 리버스 프록시 설정 및 관리 핵심 요약
Nginx를 리버스 프록시로 사용하려면 sites-enabled 디렉토리 내 설정 파일을 수정해야 해. 특정 URL 경로에 대한 요청을 백엔드 애플리케이션으로 전달할 때 location 블록과 proxy_pass 지시어를 사용하면 돼.
location /check-order {
proxy_pass http://localhost:5007; # 백엔드 서버 주소 (프로토콜, IP, 포트)
# 추가 프록시 설정 (예: proxy_set_header 등)
}
proxy_pass 뒤에 경로를 명시하지 않으면, location 블록의 경로가 백엔드로 그대로 전달돼. 설정 변경 후에는 반드시 Nginx 설정을 테스트하고 재로드해야 적용됨.
sudo nginx -t
sudo systemctl reload nginx
여기서 배울 것
- Nginx 리버스 프록시 기본 설정 방법 이해
- `proxy_pass` 지시어를 이용한 요청 포워딩
- Nginx 설정 변경 후 유효성 검사 및 재로드 명령어
- `location` 블록과 `proxy_pass` 경로 처리 방식
원본 파일 보기 (.claude/skills/tn-nginx-reverse-proxy-config/SKILL.md)
---
name: Nginx Reverse Proxy 설정
description: Use when the user asks to configure Nginx as a reverse proxy for a backend application, including setting up `proxy_pass` directives and managing URL paths, or when testing and reloading Nginx configuration.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/server 복기용 6f59f0807f22484aa872c87992504fdf.md
---
# server 복기용

요청할때
포트넘버 제외하고 쏘셈

sites-enable 반드시 고쳐줘야됨

location /check-order {
proxy_pass [http://localhost:5007](http://localhost:5007/);
1. Test the Nginx configuration:
```bash
sudo nginx -t
```
2. If the test is successful, reload Nginx:
```bash
sudo systemctl reload nginx
```
This
In the context of Nginx proxying, the **`proxy_pass`** directive specifies the protocol, address, and port of the upstream server to which the request should be forwarded. The path part of the **`proxy_pass`** directive is optional and is used when the path on the upstream server is different from the path specified in the **`location`** block.
Given your scenario, where the Flask application running on port 5007 handles the path **`/check-order`**, you have two options:
1. **Omit the path in `proxy_pass`** if your Flask application is expecting the path as part of the request. This is common when the Flask app itself is configured to handle specific routes.
```
nginxCopy code
location /check-order {
proxy_pass http://localhost:5007;
# Other proxy settings...
}
```
Here, a request to **`https://ec2.flaresolution.com/check-order`** will be passed to **`http://localhost:5007/check-order`**.
2. **Include the path in `proxy_pass`** if you need to rewrite the URL path when forwarding to the upstream server.
```
nginxCopy code
location /check-order {
proxy_pass http://localhost:5007/check-order;
# Other proxy settings...
}
```
This is functionally the same as the first option, given your specific use case. The request URI is passed to the server in the same form as it was received.
두개는 똑같다고함