前言

系统环境是Centos 7,nginx选用的是openresty 版本

系统优化
systemctl disable firewalld
systemctl stop firewalld
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
yum -y install iptables iptables-services net-tools vim
yum -y install epel-release 
echo "* soft nofile 65535 
* hard nofile 65535" >>/etc/security/limits.conf

编译OpenResty

下载

wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar zxmf openresty-1.13.6.2.tar.gz

编译

cd openresty-1.13.6.2/
yum -y install gcc gcc-c++  pcre pcre-devel  zlib zlib-devel openssl openssl-devel curl autoconf automake
./configure --with-http_gzip_static_module
gamke & gmake install

ln -s /usr/local/openresty/nginx/conf /etc/nginx
提示:上述命令默认编译参数:
参数 参数说明 详细说明
--prefix=/usr/local/openresty/nginx 安装目录
--with-cc-opt=-O2
--add-module=../ngx_devel_kit-0.3.0
--add-module=../echo-nginx-module-0.61 调试nginx.conf中的location时的模块 https://blog.csdn.net/rex_nie/article/details/79305097
--add-module=../xss-nginx-module-0.06 跨域 AJAX 支持.当前仅支持 GET .
--add-module=../ngx_coolkit-0.2rc3
--add-module=../set-misc-nginx-module-0.32 URI转义模块 http://www.ttlsa.com/nginx/nginx_set-misc-nginx-module-module-description/
--add-module=../form-input-nginx-module-0.12 解析post请求中的参数 https://www.cnblogs.com/linxiong945/p/4284434.html
--add-module=../encrypted-session-nginx-module-0.08 http://ju.outofmemory.cn/entry/35811
--add-module=../srcache-nginx-module-0.31 页面缓存 https://blog.csdn.net/caihaobin8023/article/details/56480092
--add-module=../ngx_lua-0.10.13 lua 脚本
--add-module=../ngx_lua_upstream-0.07
--add-module=../headers-more-nginx-module-0.33
--add-module=../array-var-nginx-module-0.05
--add-module=../memc-nginx-module-0.19
--add-module=../redis2-nginx-module-0.15
--add-module=../redis-nginx-module-0.3.7
--add-module=../rds-json-nginx-module-0.15
--add-module=../rds-csv-nginx-module-0.09
--add-module=../ngx_stream_lua-0.0.5
--with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib
--with-stream
--with-stream_ssl_module
--with-http_ssl_module

configure 可以通过如下参数添加模块(http://openresty.org/cn/components.html)

参数 参数说明 使用说明
--with-http_iconv_module enable ngx_http_iconv_module
--with-http_drizzle_module enable ngx_http_drizzle_module
--with-http_postgres_module enable ngx_http_postgres_module
--with-luajit enable and build the bundled LuaJIT 2.1 (the default)
--with-select_module enable select module
--with-poll_module enable poll module
--with-threads enable thread pool support
--with-file-aio enable file AIO support
--with-ipv6 enable IPv6 support
--with-http_v2_module enable ngx_http_v2_module
--with-http_realip_module 获取用户真实IP https://blog.csdn.net/cscrazybing/article/details/50789234
--with-http_addition_module enable ngx_http_addition_module
--with-http_xslt_module enable ngx_http_xslt_module
--with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module
--with-http_image_filter_module enable ngx_http_image_filter_module
--with-http_image_filter_module=dynamic
--with-http_geoip_module enable ngx_http_geoip_module
--with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module
--with-http_sub_module enable ngx_http_sub_module
--with-http_dav_module enable ngx_http_dav_module webdav 支持
--with-http_flv_module enable ngx_http_flv_module
--with-http_mp4_module enable ngx_http_mp4_module
--with-http_gunzip_module enable ngx_http_gunzip_module
--with-http_gzip_static_module enable ngx_http_gzip_static_module https://blog.csdn.net/qq_36431213/article/details/78221189
--with-http_auth_request_module enable ngx_http_auth_request_module 第三方认证支持 https://www.cnblogs.com/wangxiaoqiangs/p/6184181.html
--with-http_random_index_module enable ngx_http_random_index_module
--with-http_secure_link_module enable ngx_http_secure_link_module
--with-http_degradation_module enable ngx_http_degradation_module
--with-http_slice_module enable ngx_http_slice_module
--with-http_stub_status_module enable ngx_http_stub_status_module
--with-http_perl_module enable ngx_http_perl_module
--with-http_perl_module=dynamic enable dynamic ngx_http_perl_module
--with-mail enable POP3/IMAP4/SMTP proxy module mail 代理
--with-mail=dynamic enable dynamic POP3/IMAP4/SMTP proxy module
--with-mail_ssl_module enable ngx_mail_ssl_module
--with-stream enable TCP/UDP proxy module
--with-stream=dynamic enable dynamic TCP/UDP proxy module
--with-stream_ssl_module enable ngx_stream_ssl_module
--with-stream_realip_module enable ngx_stream_realip_module 获取访问者真实IP
--with-stream_geoip_module enable ngx_stream_geoip_module
--with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
--with-stream_ssl_preread_module enable ngx_stream_ssl_preread_module
--with-google_perftools_module enable ngx_google_perftools_module
--with-cpp_test_module enable ngx_cpp_test_module

https://blog.csdn.net/johnnycode/article/details/41847745

添加nginx用户

groupadd nginx
useradd -d /var/lib/nginx -m -s /sbin/nologin -g nginx -c "Nginx web server" nginx

nginx配置

cd /usr/local/openresty/nginx/conf
cat >/usr/local/openresty/nginx/conf/nginx.conf <gzip.conf<default <

注册系统服务

cat >/usr/lib/systemd/system/nginx.service <