nginx安装-openresty版本
原创
©著作权归作者所有:来自51CTO博客作者aayulong的原创作品,请联系作者获取转载授权,否则将追究法律责任
1、安装依赖
yum install -y wget gcc gcc-c++ perl make kernel-headers kernel-devel libpcre3-dev openssl libssl-dev libxml2-dev libgd-dev libxml2 libgeoip-dev libxslt-dev openssl-devel zlib zlib-devel pcre pcre-devel autoconf libxml2 libpcre3 g++ perl-devel perl-ExtUtils-Embed gd gd-devel libxslt-devel geoip-devel
2、上传并解压openresty
tar -zxf openresty-1.21.4.1.tar.gz
cd openresty-1.21.4.1
3、编译
./configure --prefix=/usr/local/openresty --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-compat --with-pcre-jit
4、安装
5、添加环境
vi /etc/profile
export OPENRESTY_PATH=/usr/local/openresty
export LUAJIT_PATH=/usr/local/openresty/luajit
export NGINX_PATH=/usr/local/openresty/nginx
export PATH=$PATH:$LUAJIT_PATH/bin:$OPENRESTY_PATH/bin:$NGINX_PATH/sbin
source /etc/profile
6、开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
查看开放的端口:firewall-cmd --list-ports
7、开机启动
vi /usr/lib/systemd/system/openresty.service
[Unit]
Description=openresty service
After=network.target
[Service]
Type=forking
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
8、加入开机启动
systemctl enable openresty.service #加入
systemctl disable openresty.service #停止
9、启动、重启、停止服务
systemctl start openresty.service #启动
systemctl stop openresty.service #停止
systemctl restart openresty.service #重启
ps -ef | grep openresty #验证是否启动启动成功
10、测试
curl http://192.168.31.191/
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Welcome to OpenResty!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to OpenResty!</h1>
<p>If you see this page, the OpenResty web platform is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to our
<a href="https://openresty.org/">openresty.org</a> site<br/>
Commercial support is available at
<a href="https://openresty.com/">openresty.com</a>.</p>
<p>We have articles on troubleshooting issues like <a href="https://blog.openresty.com/en/lua-cpu-flame-graph/?src=wb">high CPU usage</a> and
<a href="https://blog.openresty.com/en/how-or-alloc-mem/">large memory usage</a> on <a href="https://blog.openresty.com/">our official blog site</a>.
<p><em>Thank you for flying <a href="https://openresty.org/">OpenResty</a>.</em></p>
</body>
</html>