记录一些常用的函数和瞎折腾的过程……

nginx配置代理

提醒:本文最后更新于 1749 天前,文中所描述的信息可能已发生改变,请谨慎使用。

出于某些原因,我们要使用自己的域名去代理某个网站,当访问自己的网站域名时,出现的内容是想真实访问的网站内容,这个时候就需要配置代理了。这里以nginx为例,我自己参照网上的教程配置了一个,仅供参考:

server {
	listen 80;
	server_name www.yourdomain.com;
	return 301 https://$host$request_uri;
	location / {
		proxy_pass    https://www.proxydomain.com;			
		sub_filter    www.proxydomain.com   www.yourdomain.com;
		sub_filter_once                     off;			
		proxy_http_version                  1.1;
		proxy_cache_bypass                  $http_upgrade;
		proxy_set_header Upgrade            $http_upgrade;
		proxy_set_header Connection         "upgrade";
		proxy_set_header Referer            https://www.proxydomain.com;
		proxy_set_header Host               www.proxydomain.com;
		proxy_set_header X-Real-IP          $remote_addr;
		proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Host   $host;
		proxy_set_header X-Forwarded-Proto  $scheme;
		proxy_set_header X-Forwarded-Port   $server_port;
		proxy_set_header Accept-Encoding    "";
	}
	access_log off;
}

server {
	listen 443 ssl http2;
	server_name www.yourdomain.com;
	ssl_certificate /SSL/your.pem;
	ssl_certificate_key /SSL/your.key;
	ssl_session_timeout 5m;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
	ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
	ssl_session_cache builtin:1000 shared:SSL:10m;
	ssl_dhparam /SSL/dhparam.pem;	
	location / {
		proxy_pass   https://www.proxydomain.com;
		sub_filter   www.proxydomain.com    www.yourdomain.com;
		sub_filter_once off;
		proxy_http_version                  1.1;   
		proxy_cache_bypass                  $http_upgrade;
		proxy_set_header Upgrade            $http_upgrade; 
		proxy_set_header Connection         "upgrade";      
		proxy_set_header Referer            https://www.proxydomain.com;
		proxy_set_header Host               www.proxydomain.com;						
		proxy_set_header X-Real-IP          $remote_addr;
		proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Host   $host;
		proxy_set_header X-Forwarded-Proto  $scheme;
		proxy_set_header X-Forwarded-Port   $server_port;
		proxy_set_header Accept-Encoding    "";	
	}
	access_log off;
}