sudo apt-get update
sudo apt-get install nginx
sudo vi /etc/nginx/sites-available/default
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080/;
}
}
이렇게만 해줘도 localhost:80 으로 접근하면 localhost:8080 으로 리다이렉트 되는 것을 확인할 수 있습니다.
그래서 여러 서버를 띄워서 로드밸런싱을 하고 싶을 수도 있습니다.
sudo vi /etc/nginx/sites-available/default
upstream backend {
server localhost:8080;
server localhost:8081;
server localhost:8082;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://backend/;
}
}
간단하게 말하자면 localhost로 들어오는 요청을 localhost:8080, localhost:8081, localhost:8082 로 분산시키는 것입니다.
sudo nginx -s reload
또는
sudo service nginx restart
sudo vi /etc/nginx/sites-available/default
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080/;
}
}
server_name 이 외부에서 접근할 도메인입니다.
DNS 설정을 했다면 현재 우분투 서버의 IP 주소로 접근 할 수 있겠죠
거기서 오는 요청을 Nginx 에서 localhost:8080 으로 리다이렉트 시켜주는 것입니다.
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo certbot
sudo certbot --nginx
보통 이 아래를 많이 쓴다!!
sudo certbot --nginx -d accounts.example.com
example.com 은 도메인이다. 자신의 도메인을 넣어 주면 된다.
sudo certbot renew --dry-run
certbot으로 생성한 SSL 인증서 갱신 할 수 있는지 여부 확인 하기 갱신이 되는 건 아님
sudo certbot renew
certbot 으로 생성한 SSL 인증서 갱신
sudo certbot delete
certbot으로 생성한 SSL 인증서 삭제
sudo vi /etc/nginx/sites-available/default
upstream tomcatAuth {
ip_hash;
server 127.0.0.1:8100; # account.example.com 으로 들어온 요청은 127.0.0.1:8100 으로 리다이렉트
}
server {
#
server_name accounts.example.com;
location / {
proxy_pass http://tomcatAuth; # 위 upstream 에서 설정한 이름
proxy_set_header HOST $http_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;
proxy_redirect off;
charset utf-8;
}
# 이 아래는 certbot 으로 자동으로 만들어지게 된다.
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/accounts.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/accounts.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
# 이 아래는 자동으로 만들어진다. certbot에 의해서 자동으로 만들어짐 https 로 리다이렉트 시키는 부분
server {
if ($host = accounts.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name accounts.gdsc-dju.com;
listen 80;
return 404; # managed by Certbot
}
sudo vi /etc/nginx/sites-available/example.conf
upstream example {
ip_hash;
server
[...]
default 는 삭제 해야 한다.
sudo rm /etc/nginx/sites-enabled/default
그냥 conf 파일을 만들어서 위에 있는 내용을 자기 입맛대로 고쳐 쓰면 된다.
필요한 도메인 만큼 conf 파일을 만들어서 사용하면 된다.
sudo service nginx restart
웅찬이 쵝오