安裝篇——nginx安裝ssl模塊轉發https請求


一、查看nginx安裝的所有模塊,執行命令:

  cd  /usr/local/nginx/sbin

  ./nginx -V

  是否存在模塊http_ssl_module,如果已存在直接進行第三步,否則進行第二步;

二、給已經安裝的nginx添加http_ssl_module模塊

  1、查看已安裝的nginx版本,執行命令:

  cd /usr/local/nginx/sbin

  ./nginx -V

  2、下載對應版本的nginx源碼壓縮包(本人的是nginx/1.16.0),下載到目錄  /usr/local  后進行編譯,執行命令:

  unzip nginx-1.16.0.zip;

  cd nginx-1.16.0; 

  ./configure  ###這里添加的是原來已安裝的模塊,即:上文查看nginx是否安裝http_ssl_module模塊時查詢出來的已安裝模塊,在結尾加上要添加的模塊(例如:./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --add-module=/usr/local/fastdfs-nginx-module/src --with-http_stub_status_module --with-http_ssl_module);

  make;

  3、make完之后,也就是編譯完成之后會在當前目錄下的objs下生成一個剛剛編譯的nginx二進制文件,將已安裝nginx上的與之替換

  mv /usr/local/nginx/sbin/nginx  /usr/local/nginx/sbin/nginx_bak

  cp /usr/local/nginx-1.16.0/sbin/nginx  /usr/local/nginx/sbin/nginx

三、安裝ssl證書

  1、上傳在阿里雲或其他地方購買的ssl證書到nginx安裝目錄

  cd /usr/local/nginx

  mkdir cert

  cd cert

  rz  ####上傳ssl證書

  #####配置nginx

  cd ../conf

  vim nginx.conf    #####配置如下:

 

server { listen 443 ssl; server_name 域名/ip; ssl_certificate ###證書的pem文件路徑,例如(/usr/local/nginx/cert/1.pem); ssl_certificate_key ###證書的key文件路徑,例如(/usr/local/nginx/cert/2.key); ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ####配置的轉發地址 location /api { proxy_pass http://127.0.0.1:21010;
 proxy_set_header Host $host; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }

 

 

 

  2、重新啟動nginx

 

  cd /usr/local/nginx/sbin

 

  ./nginx -c /usr/local/nginx/conf/nginx.conf

 


免責聲明!

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



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