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

https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E
步驟非常詳細。
安裝nginx 參照:
http://mrdeng.blog.51cto.com/3736360/1735313
編譯的時候需要制定ssl模塊:
--with-http_ssl_module ,啟用nginx對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; #允許客戶端請求的大單個文件字節數
client_body_buffer_size 128k; #緩沖區代理緩沖用戶端請求的大字節數
proxy_connect_timeout 600; #跟后端服務器連接超時時間,發起握手等候響應超時時間
proxy_read_timeout 600; #連接成功后,等候后端服務器響應時間,在后端排隊中等候
proxy_send_timeout 600; #后端服務器數據回傳時間,就是在規定時間內后端服務器必須傳完有數
proxy_buffer_size 16k; #代理請求緩存區,這個緩存區間會保存用戶的信息以供nginx進行則處理,一般只要能保存下頭
信息即可
proxy_buffers 4 32k; #同上,告訴nginx保存單個用的幾個Buffer大用多大空間
proxy_busy_buffers_size 64k; #如果系統很忙可以申請用的幾個更大的proxy_buffer
proxy_temp_file_write_size 64k; #緩存臨時文件大小
#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;
}
配置文件就是這樣,你可以訪問 http://www.xxx.com 會自動跳轉到https://www.xxx.com
這里使用的是nginx的rewrite功能 permanent 是實現永久跳轉。
注意:
我在弄的時候 沒有開443端口,整的最后搞了幾個小時,偶然發現,端口沒有開。注意細節,防火墻一定開端口。
筆記隨筆,請大家多多指正。
另外有需要云服務器可以了解下創新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網站標題:nginx反向代理http和https配置-創新互聯
網站鏈接:http://www.yijiale78.com/article24/cspdje.html
成都網站建設公司_創新互聯,為您提供關鍵詞優化、定制開發、網站改版、App設計、Google、外貿建站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯