Nginx 리버스 프록시 설정
Nginx로 백엔드 프록시 걸기, 경로 처리 확인.
Nginx 리버스 프록시 설정할 때
sites-enabled 파일 반드시 수정해야 함.
location /check-order {
proxy_pass http://localhost:5007;
# 다른 프록시 설정들...
}
요청할 때 포트 넘버 제외하고 쏨.
proxy_pass 뒤에 경로 붙이는거랑 안 붙이는거랑 이 경우엔 똑같음.
proxy_pass http://localhost:5007;:/check-order요청이http://localhost:5007/check-order로 전달됨.proxy_pass http://localhost:5007/check-order;: 위와 동일하게 동작함.
설정 변경 후
sudo nginx -t
-t : Nginx 설정 파일 문법 검사. 이상 없으면 성공.
sudo systemctl reload nginx
reload : Nginx 서비스 재시작 없이 설정만 다시 불러옴.
여기서 배울 것
- Nginx `sites-enabled` 파일 수정 필수.
- `proxy_pass` 경로 처리 방식 이해 중요.
- 설정 변경 후 `nginx -t`로 테스트, `systemctl reload nginx`로 적용.
- Nginx가 포트 넘버는 알아서 처리함.
원본 파일 보기 (.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.
두개는 똑같다고함