安装OpenResty
安装OpenResty
- 安装依赖
1
yum install -y pcre-devel openssl-devel gcc curl make wget geoip geoip-devel
- 下载安装包
1
2mkdir -p /root/source
wget https://openresty.org/download/openresty-1.21.4.1.tar.gz -O /root/source/openresty-1.21.4.1.tar.gz - 解压
1
tar -zxvf /root/source/openresty-1.21.4.1.tar.gz
- 安装
1
2
3
4cd /root/source/openresty-1.21.4.1/
./configure --with-http_realip_module --with-http_geoip_module --with-http_geoip_module=dynamic --with-http_gzip_static_module --with-http_v2_module --with-luajit
make
make install - 配置系统服务
1
vim /usr/lib/systemd/system/openresty.service
1
2
3
4
5
6
7
8
9
10
11
12
13[Unit]
Description=openresty
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload
ExecStop=/usr/local/openresty/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target1
2systemctl daemon-reload
systemctl start openresty
注意事项:
- 修改配置文件隐藏nginx头
1
2
3
4
5
6
7vim /root/source/openresty-1.21.4.1/bundle/nginx/src/http/ngx_http_header_filter_module.c # 49-50行
内容:
static char ngx_http_server_string[] = "Server: nginx" CRLF;
static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF
更改为:
static char ngx_http_server_string[] = "Server: X-Web" CRLF;
static char ngx_http_server_full_string[] = "Server:X-Web " CRLF; - 载入外部依赖,必须放在events前面
1
load_module modules/ngx_http_geoip_module.so;
- 配置允许访问国家
1
2
3
4
5geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allowd_country {
default no;
CN yes;
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Qiko!