LoginSignup
3
2

More than 5 years have passed since last update.

Amazon(AWS)EC2でのNginxを最低限動かせる設定 nginx.conf

Last updated at Posted at 2018-08-15

それぞれの最低限の設定

とりあえず「Welcome to nginx on the Amazon Linux AMI!」の画面を表示させる設定

nginx.conf
user                    nginx;
worker_processes        auto;
error_log               /var/log/nginx/error.log;
pid                     /var/run/nginx.pid;

events {
        worker_connections              1024;
}

http{
        server{
                listen                  80;
                listen                  [::]:80;
                server_name             sample.com;
                root                    /usr/share/nginx/html;

                location / {
                        root                    /var/www/html;
                        index                   index.php index.html index.htm;
                }

        }
}

2018-08-15_13h51_13.png

ただ、プロセスを正常?起動させるためだけなら下記で大丈夫(らしい)

nginx.conf
events{}

「Welcome to nginx on the Amazon Linux AMI!」の画面は表示されません

デフォルトで設定されてる形

nginx.conf
user                    nginx;
worker_processes        auto;
error_log               /var/log/nginx/error.log;
pid                     /var/run/nginx.pid;

events {
        worker_connections      1024;
}

http{

        log_format  main        '$remote_addr - $remote_user [$time_local] "$request" '
                                '$status $body_bytes_sent "$http_referer" '
                                '"$http_user_agent" "$http_x_forwarded_for"';

        access_log              /var/log/nginx/access.log  main;

        sendfile                on;
        tcp_nopush              on;
        tcp_nodelay             on;
        keepalive_timeout       65;
        types_hash_max_size     2048;

        include                 /etc/nginx/mime.types;
        default_type            application/octet-stream;

        server{
                listen                  80;
                listen                  [::]:80;
                server_name             sample.com;
                root                    /usr/share/nginx/html;

                location / {
                        index                   index.php index.html index.htm;
                }

        }
}

※gzipはオンにしたほうが良いだろうか…更新多いコンテンツ提供する場合プロキシ―サーバーやキャッシュサーバーで少々問題が発生するので…
※セキュリティ的なものは下記を参照してください。

セキュリティ的に付け加えたもの

nginx.conf
user                    nginx;
worker_processes        auto;
error_log               /var/log/nginx/error.log;
pid                     /var/run/nginx.pid;

events {
        worker_connections      1024;
}

http{

        log_format  main        '$remote_addr - $remote_user [$time_local] "$request" '
                                '$status $body_bytes_sent "$http_referer" '
                                '"$http_user_agent" "$http_x_forwarded_for"';

        access_log              /var/log/nginx/access.log  main;

        sendfile                on;
        tcp_nopush              on;
        tcp_nodelay             on;
        keepalive_timeout       65;
        types_hash_max_size     2048;

        include                 /etc/nginx/mime.types;
        default_type            application/octet-stream;

        server_tokens           off;
        add_header              X-Frame-Options SAMEORIGIN;
        add_header              X-XSS-Protection "1; mode=block";
        add_header              X-Content-Type-Options nosniff;

        server{
                listen                  80;
                listen                  [::]:80;
                server_name             sample.com;
                root                    /usr/share/nginx/html;

                location / {
                        index                   index.php index.html index.htm;
                }

        }
}

バージョンを非表示したり、クリックジャッキング対策やクロスサイトスクリプティングの文言を追記してます。
追記したのは下記。

nginx.conf
        server_tokens           off;
        add_header              X-Frame-Options SAMEORIGIN;
        add_header              X-XSS-Protection "1; mode=block";
        add_header              X-Content-Type-Options nosniff;

設定前
2018-08-15_14h07_59.png

設定後
2018-08-15_14h08_47.png

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2