CentOS Nginx (1.16.1) https


非YUM源安裝Nginx,便於配置https

1 下載Nginx: http://nginx.org/en/download.html,將*.tar.gz上傳到CentOS服務器,或者通過如下方式獲取

wget https://nginx.org/download/nginx-1.16.1.tar.gz

 

2. 解壓並安裝

解壓:
tar zxvf nginx-1.16.1.tar.gz
配置安裝路徑及https支持:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
開始安裝:
make && make install

 

3. 配置nginx.conf,文件路徑位於 /usr/local/nginx/conf/,放開如下代碼並修改對應文件位置。

    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      /xxx/xxxx.crt;
        ssl_certificate_key  /xxx/xxxx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   /xxx/xxx;
            index  index.html index.htm;
     }
    }

4. 如果需要默認80端口跳轉443,即http跳轉至https,在nginx.conf代碼段server 監聽80內添加:

rewrite ^(.*)$ https://$host$1 permanent;

 

5. 啟動nginx

啟動:
/usr/local/nginx/sbin/nginx -s start
重啟:
/usr/local/nginx/sbin/nginx -s reload
停止:
/usr/local/nginx/sbin/nginx -s stop

 


免責聲明!

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



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