Nginx 搭建镜像站
# 查看Nginx 版本
nginx -v
# 下载对应版本Nginx源码包 解压
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -xvzf nginx-1.20.1.tar.gz
# 下载对应版本Nginx ngx_http_substitutions_filter_module 模块
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
# 添加模块
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=../ngx_http_substitutions_filter_module-master
# 测试启动
./objs/nginx -t
service nginx stop
service nginx status
# 写入配置
server {
server_name www.example.com;
location / {
proxy_pass https://www.google.com/;
proxy_redirect https://www.google.com/ /;
proxy_cookie_domain google.com www.example.com;
proxy_set_header User-Agent $http_user_agent;
# 这里设置cookie,可根据自身情况选择是否替换
proxy_set_header Cookie "PREF=ID=047808f19f6de346:U=0f62f33dd8549d11:FF=2:LD=zh-CN:NW=1:TM=1325338577:LM=1332142444:GM=1:SG=2:S=rE0SyJh2W1IQ-Maw";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 这里替换网页中的链接
subs_filter http://www.google.com http://www.example.com;
subs_filter https://www.google.com http://www.example.com;
}
}
# 替换 启动
cp ./objs/nginx /usr/sbin/nginx
service nginx start
# 一些错误
./configure: error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
./configure: error: SSL modules require the OpenSSL library.
yum -y install openssl openssl-devel
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
yum -y install libxml2 libxml2-dev libxslt-devel
./configure: error: the HTTP image filter module requires the GD library.
yum -y install gd-devel
./configure: error: perl module ExtUtils::Embed is required
yum -y install perl-devel perl-ExtUtils-Embed
./configure: error: the Google perftools module requires the Google perftools library. You can either do not enable the module or install the library
yum install gperftools -y
上次更新: 2024/11/05, 08:29:31