安裝環境:CentOS linux
一、 依賴庫安裝nginx
yum -y install readline-devel pcre-devel openssl-devel gcc
二、 下載源碼包,並解壓git
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
三、配置需安裝的模塊github
./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/
四、編譯安裝web
make -j2 && make install
五、製做https證書markdown
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
六、修改nginx.conf配置curl
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; ... ... ... }
七、啓動Nginxpost
/usr/local/openresty/nginx/sbin/nginx ps -ef | grep nginx netstat -ltpe | grep nginx
八、測試Nginx測試
curl -k https://192.168.155.10:8090 curl -i http://192.168.155.10:8080
九、開機自啓動(根據本身的需求設定)lua
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