没什么复杂的,直接给出 nginx 配置,使用sub_filter
替换,根本用不上以前说过的第三方模块subs_filter
server {
listen 80;
listen [::]:80;
server_name hostloc.eu.org;
#SSL Configuration
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /ssl/hostloc.eu.org.crt;
ssl_certificate_key /ssl/hostloc.eu.org.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
# proxy to another site
location ~/ {
proxy_pass https://hostloc.com;
proxy_set_header Host hostloc.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header referer https://hostloc.com/$request_uri;
proxy_set_header Accept-Encoding "";
proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0";
sub_filter_types *;
sub_filter '<base href="https://hostloc.com/">' '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" type="text/css" href="//hostloc.eu.org/responsive.css" />';
sub_filter 'hostloc.com' 'hostloc.eu.org';
sub_filter '</body>' '<script src="//hostloc.eu.org/polish.js"></script></body>';
sub_filter_once off;
set $static_fileEJLfi5A0 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_fileEJLfi5A0 1;
expires 12h;
}
if ( $static_fileEJLfi5A0 = 0 )
{
add_header Cache-Control no-cache;
}
}
location /responsive.css {
root /www/hostloc.eu.org/;
}
location /polish.js {
root /www/hostloc.eu.org/;
}
}
必备的 css 和 js 文件,放到/www/hostloc.eu.org/下就行
https://hostloc.ir/static2/css/responsive.css
https://hostloc.ir/static2/js/polish.js
-----------
原文:https://blog.iplayloli.com/everyone-uses-nginx-to-reverse-proxy-hostloc.html
文章评论