周囲
Centos7.6
nginx-1.17.0
ダウンロード
公式サイト:http://nginx.org/download/nginx-1.17.0.tar.gz
環境確認
インストール中にnginx
システムがインストールされているかどうかを確認するために、最初の前にgcc
、pcre-devel
、zlib-devel
、openssl-devel
- パッケージがインストールされているかどうかを確認します
yum list installed | grep xxx
- パッケージをインストールする
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
上の写真がインストールされています
インストール
- ウィル
nginx-1.17.0.tar.gz
サーバーと解凍にアップロード
tar -xzvf nginx-1.17.0.tar.gz
解凍後は、次のようになります。
nginx
ディレクトリの下にコンパイルしてインストールしますnginx
./configure --prefix=/usr/local/nginx1.17.0 --conf-path=/usr/local/nginx1.17.0/nginx.conf --with-http_stub_status_module --with-http_ssl_module
--with-http_ssl_module
構成nginx
サポートhttps
プロトコルアクセス、使用しないでhttps
コマンドを追加できません
このコマンドは、ディレクトリに生成されnginx
た構成ファイルをコンパイルします。これnginx.conf
はnginx
、コンパイラエラーがこのようにエラーログの裏側を参照しているため、nginx
構成ファイルが存在しないためconf
です。のnginx.conf
- 順次実行
make
、make install
コンパイル
make
make install
- インストールが成功したかどうかをテストします
./sbin/nginx -t
- 起動
nginx
./sbin/nginx
- やめる
nginx
./sbin/nginx -s stop
- リブート
nginx
./sbin/nginx -s reload
nginx
プロセスを表示
ps -ef | grep nginx
- アクセス:ブラウザがサーバーにアクセスし
IP
(nginx
デフォルトのポートは80
)、次のインターフェイスが成功を証明しているように見えます
HTTPSを構成する
- サーバー
openssl
にインストールされ、openssl-devel
yum install openssl openssl-devel
- 証明書ストレージディレクトリを作成します
mkdir /usr/local/nginx/conf/ssl
- サーバーの秘密鍵を作成する
openssl genrsa -des3 -out server.key 2048 #根据提示输入证书口令
- 署名リクエストの証明書を作成する(
CSR
)
openssl req -new -key server.key -out server.csr #输入上面设置的口令,根据提示输入相应的信息
key
復号化
openssl rsa -in server.key -out server_nopasswd.key
- 上記の秘密鍵を使用して証明書に署名し、
CSR
openssl x509 -req -days 365 -in server.csr -signkey server_nopasswd.key -out server.crt
vim
nginx
構成ファイルを変更し、ssl
証明書をロードします
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx-1.17.0/conf/ssl/server.crt;
ssl_certificate_key /usr/local/nginx-1.17.0/conf/ssl/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
-
証明書のパスワードを入力して開始します
nginx
-
ブラウザアクセステスト:
https://服务器IP + 端口443
次のインターフェイスが表示された場合、成功します
エラーログ
nginx
エラー:cp: `conf/koi-win' and `/usr/local/nginx/conf/koi-win' are the same file
問題のあるコマンドであるコンパイルおよびインストールnginx
時にエラーが指定されていませんconf-path
。
./configure --prefix=/usr/local/nginx1.17.0 --with-http_stub_status_module --with-http_ssl_module
コマンドを次の仕様conf-path
に変更した後は正常です。
./configure --prefix=/usr/local/nginx1.17.0 --conf-path=/usr/local/nginx1.17.0/nginx.conf --with-http_stub_status_module --with-http_ssl_module