Created
May 3, 2022 14:12
-
-
Save sitsh/0552a01e537ae169a9a9a43955f775cc to your computer and use it in GitHub Desktop.
nginx proxy config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name localhost; #改成自己的域名 | |
root "/home/wwwroot/default"; #改自己的服务器目录 | |
set $custom_host "https://www.baidu.com"; | |
set $custom_host3 "/"; | |
set $custom_host5 "/"; | |
if ($request_uri ~* ^\/((http|https)://(www.)?(\w+(\.)?)+)(.*?)$) { | |
set $custom_host $1; | |
set $custom_host3 $6; | |
} | |
if ($custom_host3 = ""){ | |
set $custom_host3 "/"; | |
} | |
if ($custom_host3 = " "){ | |
set $custom_host3 "/"; | |
} | |
if ($request_uri ~* ^\/((http|https)://(www.)?(\w+(\.)?)+)(.+)\?(.+)$) { | |
set $custom_host3 $6; | |
} | |
set $custom_host2 "www.baidu.com"; | |
if ($request_uri ~* ^\/((http|https)://)((www.)?(\w+(\.)?)+)(.*?)$) { | |
set $custom_host2 $3; | |
set $custom_host5 $1; | |
} | |
if ($request_uri ~* ^\/((http|https)://)((www.)?(\w+(\.)?)+)$) { | |
set $custom_host2 $3; | |
set $custom_host5 $1; | |
} | |
set $current "http://"; | |
if ($scheme = https) { | |
set $current "https://"; | |
} | |
location / { | |
rewrite /(.*)$ $custom_host3 break; | |
proxy_connect_timeout 100s; | |
proxy_set_header x-forwarded-for $remote_addr; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
set $ishttp "http"; | |
if ($custom_host5 = https://) { | |
set $ishttp "https"; | |
} | |
proxy_set_header X-Forwarded-Proto $ishttp; | |
proxy_set_header Host $custom_host2; | |
proxy_cache_key $host$uri$is_args$args; | |
proxy_headers_hash_max_size 512; | |
proxy_headers_hash_bucket_size 128; | |
proxy_buffer_size 64k; | |
proxy_buffers 32 64k; | |
proxy_busy_buffers_size 128k; | |
proxy_set_header Cookie $http_cookie; | |
proxy_cache_methods GET; | |
proxy_cache_methods POST; | |
proxy_cache_methods HEAD; | |
proxy_redirect off; | |
proxy_set_header Referer $http_referer; | |
proxy_set_header User-Agent $http_user_agent; | |
# 防止谷歌返回压缩的内容,因为压缩的内容无法替换字符串 | |
proxy_set_header Accept-Encoding ""; | |
#proxy_connect_timeout 15000; | |
proxy_send_timeout 15000; | |
proxy_read_timeout 15000; | |
sub_filter_types *; | |
proxy_cache_valid 200 304 301 1s; | |
add_header MJJCDN-Cache "$upstream_cache_status"; | |
# proxy_temp_file_write_size 512000k; | |
resolver 8.8.8.8; #改为自己想要的DNS | |
proxy_set_header Accept-Encoding ""; | |
sub_filter_types *; | |
sub_filter_once off; | |
proxy_temp_file_write_size 512000k; | |
sub_filter "<head" '<base href="$current$host/$custom_host/" />\n<head'; | |
sub_filter "\"//" '"https://'; | |
sub_filter '"/' '"'; | |
sub_filter '"/search' '"search'; | |
sub_filter '"/images' '"images'; | |
sub_filter ', /images' ', images'; | |
sub_filter "http://$custom_host2" "$current$host/$custom_host"; | |
sub_filter "https://$custom_host2" "$current$host/$custom_host"; | |
proxy_pass $custom_host; | |
# # set $request_uri "qqqq"; | |
# add_header Content-Type "text/plain;charset=utf-8"; | |
# return 200 "Your IP Address:$custom_host2</br>$request_uri"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment