nginx http요청을 https로 redirect

Youngkwon Kim·2022년 7월 28일
1

Django

목록 보기
3/3

1. nginx 설정 파일에 redirect 관련 코드를 추가한다.

server {
    listen 80;
    server_name *.compute.amazonaws.com;
    charset utf-8;
    client_max_body_size 128M;

    location / {
        uwsgi_pass  unix:///tmp/mysite.sock;
        include     uwsgi_params;
    }

	# 여기서부터
    if ($http_x_forwarded_proto = 'http'){
        return 301 https://$host$request_uri;
    }
    # 여기까지
}

2. nginx와 uwsgi restart

$ sudo systemctl daemon-reload && sudo systemctl restart nginx uwsgi

3. https로 접근 완료

0개의 댓글