Nginx監聽443端口配置SSL證書


先去寶塔:https://www.bt.cn/申請一個免費SSL證書:
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
點支付訂單后,還需要再列表 驗證域名,驗證域名需要在自己的域名解析配置txt類型字符串值如下,解析值在寶塔SSL申請列表詳情可以看到:
在這里插入圖片描述
驗證成功后,在SSL申請列表下載證書:
在這里插入圖片描述
下載后是一個壓縮包,壓縮包里會有各種服務器配置需要的證書
在這里插入圖片描述
在這里插入圖片描述
SSL免費證書申請好了,那么我就來看看nginx監聽443端口配置SSL證書吧
如果還沒安裝nginx請看我另外一篇博文安裝nginx教程:https://blog.csdn.net/lc8023xq/article/details/107430072

nginx配置:

http {
    include       mime.types;
    default_type  application/octet-stream;
    gzip on;
    gzip_min_length 1024;
    gzip_types text/css application/x-javascript application/vnd.api+json;
    gzip_disable "MSIE [1-6]\.";
    gzip_comp_level 2;

    #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 logs/access.log main;

    sendfile        on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout  65;

    #gzip on;
	server {
        listen       443 ssl;
        server_name  javakfz.com;
        root   /home/www/discuz/public;
        index  index.php;
		#ssl on;
    ssl_certificate  /opt/install/Nginx_SSL/1_javakfz.com_bundle.pem;
    ssl_certificate_key /opt/install/Nginx_SSL/0_javakfz.com.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
        #charset koi8-r;

        #access_log logs/host.access.log main;

        #location / {
        # try_files $uri $uri/ /index.php?$query_string;
        #}
        location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /home/www/discuz/public$fastcgi_script_name;
        }

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
		
   }
   #配置80端口重定向443端口
    server {
        listen 80;
        server_name  javakfz.com;
        rewrite ^(.*)$ https://${server_name}$1 permanent;

    }
}

如果在Nginx配置好SSL相關配置之后報錯:
檢查配置:/usr/local/nginx/sbin/nginx
報錯:nginx: [emerg] unknown directive “ssl” in /usr/local/nginx/conf/nginx.conf:26

以上說明沒有安裝SSL模塊,那么我們需要重新安裝相關模塊
1.在nginx的安裝目錄執行
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
2.在nginx的安裝目錄執行
make

最后
/usr/local/nginx/sbin/nginx -s reload # 重新載入配置文件
/usr/local/nginx/sbin/nginx -s reopen # 重啟 Nginx


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM