安装OpenResty

安装OpenResty

安装OpenResty

  1. 安装依赖

    yum install -y pcre-devel openssl-devel gcc curl make wget geoip geoip-devel
  2. 下载安装包

    mkdir -p /root/source
    wget https://openresty.org/download/openresty-1.21.4.1.tar.gz -O /root/source
  3. 解压

    tar -zxvf /root/source/openresty-1.21.4.1.tar.gz
  4. 安装

    cd /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
  5. 配置系统服务

    vim /usr/lib/systemd/system/openresty.service
    [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.target
    systemctl daemon-reload
    systemctl start openresty

注意事项:

  1. 修改配置文件隐藏nginx头

    vim /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;
  2. 载入外部依赖,必须放在events前面

    load_module modules/ngx_http_geoip_module.so;
  1. 配置允许访问国家

    geoip_country /usr/share/GeoIP/GeoIP.dat;
    map $geoip_country_code $allowd_country {
      default no;
      CN yes;
    }
Comment