swppfall2019
swppfall2019 copied to clipboard
[tip] configuring nginx to redirect http and non-www requests to https-www
안녕하세요.
example.com 만 입력하더라도 https://www.example.com 로 접속하게 해주는 nginx 설정입니다. 랩 때 작성한 부분 뒤에 추가하면 작동합니다. (it works on my azure VM)
# append to /etc/nginx/sites-available/frontend.conf
# redirect http to https (example.com, http://www.example.com, http://example.com)
server {
listen 80;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
아래의 경우, https://example.com 을 https://www.example.com 으로 리다이렉션 시켜주는 설정입니다. ssl 확인이 redirection보다 먼저 일어나서 저는 'example.com'에 대해서도 인증서를 발급 받았습니다.
$ sudo certbot certonly --manual \
--preferred-challenges dns \
--server https://acme-v02.api.letsencrypt.org/directory \
-d '*.example.com' -d 'example.com'
#redirect non-www ssl to www ssl
server {
listen 443 ssl;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}