nginx网关--openresty
OpenResty
安装环境:CentOS
1、 依赖库安装
yum -y install readline-devel pcre-devel openssl-devel gcc
2、 下载源码包,并解压
wget https://openresty.org/download/openresty-1.13.6.1.tar.gz
tar -zxvf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1/bundle
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
tar -zxvf ngx_cache_purge-2.3.tar.gz
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar -zxvf v0.3.0.tar.gz
3、配置需安装的模块
./configure --help
./configure --prefix=/usr/local/openresty --with-luajit --with-http_ssl_module --user=root --group=root --with-http_realip_module --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/
4、编译安装
make -j2 && make install
5、制作https证书
mkdir -p /usr/local/openresty/nginx/cert
cd /usr/local/openresty/nginx/cert
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
6、修改nginx.conf配置
lua_package_path '/usr/local/openresty/lualib/?.lua;/usr/local/openresty/nginx/lua/?.lua;;'; #lua文件默认路径
lua_package_cpath '/usr/local/openresty/lualib/?.so;;'; #so文件默认路径
...
server {
listen 192.168.155.10:8080;
listen 192.168.155.10:8090 ssl;
server_name localhost;
ssl_certificate /usr/local/openresty/nginx/cert/server.crt;
ssl_certificate_key /usr/local/openresty/nginx/cert/server.key;
...
...
...
}
7、启动Nginx
/usr/local/openresty/nginx/sbin/nginx
ps -ef | grep nginx
netstat -ltpe | grep nginx
8、测试Nginx
curl -k https://192.168.155.10:8090
curl -i http://192.168.155.10:8080
9、开机自启动(根据自己的需求设定)
cat >/usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
##关闭防火墙
##关闭SElinux