nginx反向代理http和https配置

nginx可以反向代理http,同樣也可以代理https,只是需要ssl證書(shū)。這里推薦一個(gè)好用的證書(shū):

成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),鄄城企業(yè)網(wǎng)站建設(shè),鄄城品牌網(wǎng)站建設(shè),網(wǎng)站定制,鄄城網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,鄄城網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E

步驟非常詳細(xì)。

安裝nginx 參照:

http://mrdeng.blog.51cto.com/3736360/1735313

編譯的時(shí)候需要制定ssl模塊:
 --with-http_ssl_module ,啟用nginx對(duì)ssl的支持。

安裝完成之后,配置反向代理的nginx的conf文件:

user  www www;

worker_processes 2;

#worker_cpu_affinity 0001 0010 0100 1000;

error_log  /opt/web/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 51200;

#multi_accept on;

}

http

{

include       mime.types; 

 default_type  application/octet-stream; 

 charset  utf-8;  

 server_names_hash_bucket_size 128;  

 client_header_buffer_size 32k; 

 large_client_header_buffers 4 32k; 

# client_max_body_size 8m; 

 sendfile on; 

 tcp_nopush     on; 

 keepalive_timeout 120;  

 fastcgi_connect_timeout 400;  

 fastcgi_send_timeout 400;  

 fastcgi_read_timeout 400; 

 fastcgi_buffer_size 64k;  

 fastcgi_buffers 4 64k;  

 fastcgi_busy_buffers_size 128k; 

 fastcgi_temp_file_write_size 128k; 

 tcp_nodelay on;  

 gzip on; 

 gzip_min_length  1k; 

 gzip_buffers     4 16k; 

 gzip_http_version 1.0; 

 gzip_comp_level 2;

 gzip_types       text/plain application/x-javascript text/css application/xml; 

 gzip_vary on; 

 server_tokens off;

client_max_body_size 512m;   #允許客戶端請(qǐng)求的最大單個(gè)文件字節(jié)數(shù)

client_body_buffer_size 128k;  #緩沖區(qū)代理緩沖用戶端請(qǐng)求的最大字節(jié)數(shù)

proxy_connect_timeout  600;   #跟后端服務(wù)器連接超時(shí)時(shí)間,發(fā)起握手等候響應(yīng)超時(shí)時(shí)間

proxy_read_timeout   600;   #連接成功后,等候后端服務(wù)器響應(yīng)時(shí)間,在后端排隊(duì)中等候

proxy_send_timeout 600; #后端服務(wù)器數(shù)據(jù)回傳時(shí)間,就是在規(guī)定時(shí)間內(nèi)后端服務(wù)器必須傳完有數(shù)

proxy_buffer_size 16k; #代理請(qǐng)求緩存區(qū),這個(gè)緩存區(qū)間會(huì)保存用戶的信息以供nginx進(jìn)行則處理,一般只要能保存下頭

信息即可

proxy_buffers 4 32k; #同上,告訴nginx保存單個(gè)用的幾個(gè)Buffer最大用多大空間

proxy_busy_buffers_size 64k; #如果系統(tǒng)很忙可以申請(qǐng)用的幾個(gè)更大的proxy_buffer

proxy_temp_file_write_size 64k; #緩存臨時(shí)文件大小

#log format

log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '

             '$status $body_bytes_sent "$http_referer" '

             '"$http_user_agent" $http_x_forwarded_for';

upstream gw2 {

               server 172.16.88.21:80 ;

        }

server {

listen 443 ;

ssl on;

ssl_certificate /opt/ssl/xxx.com.cer;

ssl_certificate_key  /opt/ssl/xxx.com.key;

        server_name  www.xxx.com;

        location / {

                   proxy_pass http://gw2;

  proxy_redirect off;

                   limit_req zone=gw6lapp burst=100 nodelay;

                   proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;

                   proxy_set_header Host $host;

  proxy_set_header X-Forwarded-Proto https;

                   proxy_set_header X-Forwarded-For $remote_addr;

                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  proxy_headers_hash_max_size 51200;

    proxy_headers_hash_bucket_size 6400;

                   }

        }

server {

listen 80;

server_name www.xxx.com;

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

       }

配置文件就是這樣,你可以訪問(wèn) http://www.xxx.com 會(huì)自動(dòng)跳轉(zhuǎn)到https://www.xxx.com

這里使用的是nginx的rewrite功能 permanent 是實(shí)現(xiàn)永久跳轉(zhuǎn)。

注意:

我在弄的時(shí)候 沒(méi)有開(kāi)443端口,整的最后搞了幾個(gè)小時(shí),偶然發(fā)現(xiàn),端口沒(méi)有開(kāi)。注意細(xì)節(jié),防火墻一定開(kāi)端口。

筆記隨筆,請(qǐng)大家多多指正。

文章名稱:nginx反向代理http和https配置
標(biāo)題URL:http://bm7419.com/article44/igcjee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、電子商務(wù)、小程序開(kāi)發(fā)、搜索引擎優(yōu)化網(wǎng)站內(nèi)鏈、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)