1. 목표
- https 를 사용하여 데이터를 주고 받을 것 이다.
2. 준비물
sudo yum install -y certbot
sudo yum install certbot-nginx
sudo systemctl stop nginx
sudo certbot --nginx
sudo systemctl restart nginx
3. cowapi.conf 수정
sudo vi /etc/nginx/nginx.conf
http {
....
upstream tomcat {
server { ec2 탄력적 ip}:{port};
}
}
server {
listen 80;
server_name cowapi.com www.cowapi.com;
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
server_name cowapi.com www.cowapi.com;
ssl_certificate {fullchain.pem};
ssl_certificate_key {privkey.pem};
ssl_session_cache shared:le_nginx_SSL:10m;
ssl_session_timeout 1440m;
ssl_protocols {ssl_protocols};
ssl_prefer_server_ciphers off;
ssl_ciphers {ciphers};
location ^~/api/ {
proxy_pass http://tomcat/;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location = /favicon.ico {access_log off; log_not_found off;}
location / {
root /home/ec2-user/
index index.html index.htm;
try_files $uri $uri/ /index.html;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
4. 이슈
- https 로 데이터를 주고 받을 수 있게 되었다.
- 하지만, 잘되던 dashboard의 구독이 되지 않고 있다.
location = /api/dashboard/ {
proxy_pass http://tomcat/dashboard;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection keep-alive;
}
- dashboard의 subscribe 요청만 따로 빼서 아래를 같이 추가해 주었다.
...
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection keep-alive;