Home 귀찮은 Nginx 리버스 프록시 셋팅 아카이빙 해두기
Post
Cancel

귀찮은 Nginx 리버스 프록시 셋팅 아카이빙 해두기

1. Nginx 설치

1
yum install nginx

2. 서버 블록 추가

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

server {
    listen 80;
    server_name {도메인 주소};
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name {도메인 주소};

    ssl_certificate {.crt 파일 경로};
    ssl_certificate_key {.key 파일 경로};

    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;

    location / {
        proxy_pass http://localhost:{리버스 프록시 태울 대상 포트};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. 혹시 모를 방화벽 열기

1
2
3
4
# 80, 443 포트 개방
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

4. SELinux 설정

1
2
3
4
5
# 이 설정으로 Nginx가 네트워크에 접근할 수 있도록 허용한다.
sudo setsebool -P httpd_can_network_connect 1

sudo semanage fcontext -a -t httpd_sys_content_t "{.crt 파일 경로}"
sudo restorecon -v {.crt 파일 경로}

5. Nginx 띄우기 전 테스트

1
sudo nginx -t

6. Nginx 띄우고 부팅 시 자동으로 실행하도록

1
2
sudo systemctl enable --now nginx
sudo systemctl restart nginx
This post is licensed under CC BY 4.0 by the author.