• [mac] Nginx 설치 및 Let's Encrypt로 SSL 설정하기
    백엔드/macOS 2021. 6. 10. 17:10
    728x90

    Nginx

    Nginx는 웹 서버 소프트웨어로, 가벼움과 높은 성능을 목표로 한다. 웹 서버, 리버스 프록시 및 메일 프록시 기능을 가진다.

     

    1. 설치

    brew install nginx

     

    2. Nginx.conf 설정

    vi /usr/local/etc/nginx/nginx.conf
    user       www www;  ## Default: nobody
    worker_processes  5;  ## Default: 1
    error_log  logs/error.log;
    pid        logs/nginx.pid;
    worker_rlimit_nofile 8192;
    
    events {
      worker_connections  4096;  ## Default: 1024
    }
    
    http {
      include    conf/mime.types;
      include    /etc/nginx/proxy.conf;
      include    /etc/nginx/fastcgi.conf;
      index    index.html index.htm index.php;
    
      default_type application/octet-stream;
      log_format   main '$remote_addr - $remote_user [$time_local]  $status '
        '"$request" $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';
      access_log   logs/access.log  main;
      sendfile     on;
      tcp_nopush   on;
      server_names_hash_bucket_size 128; # this seems to be required for some vhosts
    
      server { # php/fastcgi
        listen       80;
        server_name  domain1.com www.domain1.com;
        access_log   logs/domain1.access.log  main;
        root         html;
    
        location ~ \.php$ {
          fastcgi_pass   127.0.0.1:1025;
        }
      }
    
      server { # simple reverse-proxy
        listen       80;
        server_name  domain2.com www.domain2.com;
        access_log   logs/domain2.access.log  main;
    
        # serve static files
        location ~ ^/(images|javascript|js|css|flash|media|static)/  {
          root    /var/www/virtual/big.server.com/htdocs;
          expires 30d;
        }
    
        # pass requests for dynamic content to rails/turbogears/zope, et al
        location / {
          proxy_pass      http://127.0.0.1:8080;
        }
      }
    }

    위와 같은 예제에서 server_name을 바탕으로 아래에서 certbot을 이용해 Let's Encrypt의 SSL를 적용한다.

    따라서 domain1.com이나 domain2.com으로 ssl이 발급될 것이다.

     

    3. 재시작

    sudo brew services restart nginx

    CertBot

    CertBot은 Let's Encrypt 인증서를 자동으로 발급 및 갱신을 해주는 봇 프로그램이다.

     

    1. 설치

    brew install certbot

     

    2. 발급

    sudo certbot

     

    천천히 읽어가며 선택하면 위와 같이 SSL 인증서가 성공적으로 발급되며 자동으로 SSL 인증서 또한 갱신된다.

     

    3. 수동 갱신

    가끔 자동으로 갱신되지 않고 아래와 같이 메일을 받은 경우 다음과 같은 명령어로 수동 갱신하면 된다.

    Hello,
    
    Your certificate (or certificates) for the names listed below will expire in 11 days (on 02 Apr 22 23:04 +0000). Please make sure to renew your certificate before then, or visitors to your web site will encounter errors.
    
    We recommend renewing certificates automatically when they have a third of their total lifetime left. For Let's Encrypt's current 90-day certificates, that means renewing 30 days before expiration. See https://letsencrypt.org/docs/integration-guide/ for details.
    sudo certbot renew

    728x90

    댓글

Copyright ⓒ syudal.tistory.com