nginx
letsencrypt

Nginxの設定(www, https, IP)

More than 1 year has passed since last update.

動作環境

  • CentOS7
  • nginx/1.12.1
  • Let's Encrypt

やったこと

  • 強制https
  • wwwなしに統一
  • IP直打ち禁止
default.conf
server {
    listen 80;
    server_name www.example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen 80;
    server_name example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}

server {
    listen 80  default_server;
    server_name _;
    return 444;
}

server {
    listen 443  ssl default_server;
    server_name  _;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    return 444;
}