Code Monkey home page Code Monkey logo

my-secure-nginx's Introduction

My Secure Nginx

nginx.conf を /etc/nginx/ 直下に配置
com.example.conf とかを /etc/nginx/conf.d/ 配下に配置
SSL 類の設定は任意の場所(/etc/nginx/ssl/ とか)に配置

セキュリティチェック

MDN Observatoryで総合チェック
ImmuniWeb WebScanでもう少し詳しくチェック
CSP EvaluatorでCSPチェック
Report URIで設定のレポーティング
GTMetrixでパフォーマンスチェック

Nginxのインストールと起動(Ubuntu)

# 最新版Nginxをリポジトリに追加
curl http://nginx.org/keys/nginx_signing.key | sudo apt-key add -
VCNAME=`cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2` && sudo -E sh -c "echo \"deb http://nginx.org/packages/ubuntu/ $VCNAME nginx\" >> /etc/apt/sources.list"
VCNAME=`cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2` && sudo -E sh -c "echo \"deb-src http://nginx.org/packages/ubuntu/ $VCNAME nginx\" >> /etc/apt/sources.list"

# インストール
apt update && apt upgrade
apt install nginx

# 起動
service nginx start
service nginx status

サーバパラメータチューニング

# ulimit -n の値を65536にする(デフォルト 1024)
sudo vim /etc/security/limits.conf
### 以下を追記
root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536
###

# カーネルのパラメータチューニング
sudo vim /etc/sysctl.conf
### 以下を追記
net.core.somaxconn = 1024
net.core.netdev_max_backlog = 5000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_wmem = 4096 12582912 16777216
net.ipv4.tcp_rmem = 4096 12582912 16777216
net.ipv4.tcp_max_syn_backlog = 8096
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535
###

# 再起動して有効化
sudo reboot

AppArmorの有効化(Ubuntu)

# AppArmor (Ubuntu版SELinuxみたいなもの)のユーティリティをインストール
apt install apparmor apparmor-profiles apparmor-utils

# Nginx用の設定を作るためログをとる
cd /etc/apparmor.d/
aa-autodep nginx
aa-complain nginx

# Nginxの再起動
service nginx restart

# ログからNginxの許可設定を作成
aa-logprof
aa-enforce nginx

# AppArmorの有効化
service apparmor restart
service nginx restart
apparmor_status

参考

my-secure-nginx's People

Contributors

aofusa avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.