NginxでSSLを有効にする
nginc.confを編集する 「c:/srv/nginx/conf/nginx.conf」
末尾にある「HTTPS server」の部分のコメントアウトを削除して編集するか
以下を追加
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl_certificate c:/srv/SSL/server.crt;
ssl_certificate_key c:/srv/SSL/server.key;
#ssl_session_cache shared:SSL:1m;
#ssl_session_timeout 5m;
#ssl_ciphers HIGH:!aNULL:!MD5;
#ssl_prefer_server_ciphers on;
location / {
root c:/srv/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root c:/srv/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}※編集箇所にハイライトをつけています
「ssl_certificate」「ssl_certificate_key」の部分は 証明書を作成 で作成したファイル名を指定
location内のパスは Nginxと連携する と同じにしてください
PHPでSSLを有効にする
php.iniを編集する 「c:/srv/nginx/php8.4/php.ini」
930行目 「;extension=openssl」のコメントアウトを削除
;extension=openssl
↓
extension=opensslWindowsでSSLを有効にする
WindowsでSSL化していない方は以下を参照に「hosts」や「証明書の作成」をしてください
SSLファイルの保存場所についてはApacheと共有する為、敢えて「c:/srv/SSL」に作成しています

動作確認
全て保存したらサーバーを起動、若しくは再起動してください ※「Nginx」「PHP」
ブラウザにて「https://localhost」などでエラーがないことを確認してください
Nginx+PHP SSL化でここが嵌った
PHPロケーションの追加が必要
nginx.conf 「c:/srv/nginx/conf/nginx.conf」
server {
listen 443 ssl;
server_name localhost;
ssl_certificate c:/srv/SSL/server.crt;
ssl_certificate_key c:/srv/SSL/server.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
location / {
root c:/srv/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root c:/srv/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}同テキストの上のほうにもPHPのlocation部分がありますが、ここでも追加しないとPHP+SSLで動作しません




コメント