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)
先確認(rèn) 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(分幀傳輸,信道復(fù)用) (只支持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;
? }
}