centos 7はnginxによってSSLを構築する
9276 ワード
今日は、nginxによるHTTPSアクセスジャンプバックエンドHTTPの構築に関するチュートリアルをお届けします.
ベースアセンブリ を取り付けるダウンロードソースコードとコンパイル ダウンロードとコード(現在~/ディレクトリの下にあると仮定)
解凍
コンパイル前の構成でnginxにssl_をサポートさせるmoduleとopenssl
コンパイル
インストール完了後のnginxパスは、/usr/local/nginxです.構成環境 騰訊雲申請証明書(自己作成証明書はネット上のその他の資料を参照)
nginxディレクトリの下の2つのファイルを/usr/local/nginx/confディレクトリにコピー
nginxの構成
nginxでconfにHTTP/HTTPS構成を追加
保存終了
nginxの起動
ファイアウォールの設定
firewalldをサービスに登録して起動
TCPプロトコルの80443ポートをインターネットに露出させる実行テスト ファイアウォールポートの確認
PS:アリクラウド/テンセントクラウドを使用している場合は、XXクラウドコンソールでセキュリティポリシーグループがTCP下の80と443をオープンしているかどうかを確認する必要があります.
nginxサービスの確認
ブラウザのテスト
何か質問やアドバイスがあれば、コメントを歓迎します^^;
yum -y isntall firewalld
yum -y install gcc gcc-c++
yum -y install pcre-devel
yum -y install zlib-devel
yum -y install openssl openssl-devel
wget https://nginx.org/download/nginx-1.12.2.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
解凍
cd /opt
tar zxf nginx-1.12.2.tar.gz
tar zxf openssl-1.0.2n.tar.gz
コンパイル前の構成でnginxにssl_をサポートさせるmoduleとopenssl
cd nginx-1.12.2
./configure --with-http_ssl_module --with-openssl=/opt/openssl-1.0.2n
コンパイル
make
make install
インストール完了後のnginxパスは、/usr/local/nginxです.
nginxディレクトリの下の2つのファイルを/usr/local/nginx/confディレクトリにコピー
nginxの構成
vim /usr/local/nginx/conf/nginx.conf
nginxでconfにHTTP/HTTPS構成を追加
upstream tomcat {
server 127.0.0.1:9081 fail_timeout=0; #
}
server {
listen 443;
ssl on;
server_name host.httpsDomain.com; #
ssl_certificate 1_host.httpsDomain.com_bundle.crt; # nginx crt , [/usr/local/nginx/conf]
ssl_certificate_key 2_host.httpsDomain.com.key; # nginx crt , [/usr/local/nginx/conf]
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3; # SSL
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; #
ssl_prefer_server_ciphers on; # SSLv3 TLS
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
# note, there is not SSL here! plain HTTP is used
proxy_pass http://tomcat;
}
}
server {
listen 80;
server_name host.httpsDomain.com; #http
location / {
rewrite ^ https://$http_host$request_uri? permanent; # HTTPS
}
}
保存終了
:wq
nginxの起動
#
/usr/local/nginx/sbin/nginx
#
/usr/local/nginx/sbin/nginx -s reload
#
/usr/local/nginx/sbin/nginx -s stop
ファイアウォールの設定
firewalldをサービスに登録して起動
systemctl enable firewalld
systemctl start firewalld
TCPプロトコルの80443ポートをインターネットに露出させる
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
# 80/tcp 443/tcp
PS:アリクラウド/テンセントクラウドを使用している場合は、XXクラウドコンソールでセキュリティポリシーグループがTCP下の80と443をオープンしているかどうかを確認する必要があります.
nginxサービスの確認
ss -ntlp | grep nginx
# 80/tcp 443/tcp nginx
ブラウザのテスト
何か質問やアドバイスがあれば、コメントを歓迎します^^;