nginx配置http https http2

1. 基礎(chǔ)的nginx 配置

server {

? linsten : 80

? server_name test.com


? location/ {

? ? proxy_pass? http://127.0.0.1:8888

proxy_set_header HOST @host

? }

}

2. 配置緩存

levels 配置cache保存時是否創(chuàng)建二級目錄。

keys_zone 內(nèi)存中保存緩存的空間大小

my_cache 是使用緩存的名稱

cache 是緩存文件大小

proxy_catch_path? cache? levels=1:2 keys_zone=my_cache:10m

server {

? linsten : 80

? server_name test.com


? location/ {

? ? proxy_cache my_cache

? ? proxy_pass? http://127.0.0.1:8888

proxy_set_header HOST @host

? }

}

3. nginx 配置HTTPs (HTTPS = http? + security)

先確認 https 公鑰私鑰的在本地路徑位置。比如 公鑰 ../path_public; 私鑰../path-private

proxy_catch_path? cache? levels=1:2 keys_zone=my_cache:10m

server {

? linsten : 443;

? server_name test.com;


? ssl on;

? ssl_certificate_key? ? ../path-private;

? ssl_certificate? ../path_public;


? location/ {

? ? proxy_cache my_cache;

? ? proxy_pass? http://127.0.0.1:8888;

proxy_set_header HOST @host;

? }

}

4. http 訪問自動跳到 https

proxy_catch_path? cache? levels=1:2 keys_zone=my_cache:10m

server{

linsten? 80 default_server;

linsten? [::]:80 default_server;

server_name test.com

return 302 http://$server_name@request_uri;

}

server {

? linsten : 443;

? server_name test.com;


? ssl on;

? ssl_certificate_key? ? ../path-private;

? ssl_certificate? ../path_public;


? location/ {

? ? proxy_cache my_cache;

? ? proxy_pass? http://127.0.0.1:8888;

proxy_set_header HOST @host;

? }

}

5. nginx 配置 http2(分幀傳輸,信道復用) (只支持https)

proxy_catch_path? cache? levels=1:2 keys_zone=my_cache:10m

server{

linsten? 80 default_server;

linsten? [::]:80 default_server;

server_name test.com

return 302 http://$server_name@request_uri;

}

server {

? linsten : 443 http2;

? server_name test.com;

? http2_push_preload on; 開啟preload


? ssl on;

? ssl_certificate_key? ? ../path-private;

? ssl_certificate? ../path_public;


? location/ {

? ? proxy_cache my_cache;

? ? proxy_pass? http://127.0.0.1:8888;

proxy_set_header HOST @host;

? }

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容