Centos7安裝Openresty
通過yum安裝
在 /etc/yum.repos.d/ 下新建 OpenResty.repo 內容
[openresty]
name=Official OpenResty Repository
baseurl=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/epel-$releasever-$basearch/
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/pubkey.gpg
enabled=1
enabled_metadata=1
查看可用的openresty軟件
yum --disablerepo="*" --enablerepo="openresty" list available
當前安裝的是 openresty.x86_64 版本1.11.2.2-8.el7.centos, 內置的openssl 是 1.0.2j
安裝
yum install openresty -y
默認會安裝到 /usr/local/openresty/ 目錄下, 目錄下包含了 luajit, lualib, nginx, openssl, pcre, zlib 這些組件
如果安裝時顯示Require GeoIP, 需要先安裝geoip後再安裝openresty
yum install epel-release
yum --enablerepo=epel install geoip
使用命令行直接啓動
/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
OpenResty安裝時, 已經把路徑加入了/usr/bin, 並且添加了服務 /etc/init.d/openresty, 可以通過服務腳本啓動
systemctl start/stop/status openresty
可以通過-p參數設置工作目錄, 對應nginx的conf, html, log都可以放到這個目錄下
openresty -p /opt/my-fancy-app/
防火牆檢查和配置
# 查看狀態
systemctl status firewalld
# 查看開放的端口
firewall-cmd --zone=public --list-all
# 添加80端口
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload
設置lua配置
#cd /usr/local/openresty/nginx/conf/
#vim nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
** # '$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';**
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
######################################################
lua_package_path "/usr/local/openresty/lualib/?.lua;;";
lua_package_cpath "/usr/local/openresty/lualib/?.so;;";
include lua.conf;
######################################################
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
創建lua.conf
#vim lua.conf
server {
listen 80;
servername ;
#HelloWorld
location /lua {
default_type 'text/html';
content_by_lua 'ngx.say("hello world182.11")';
}
}
創建lua目錄
#mkdir /usr/local/openresty/nginx/html/lua
重啓服務
#/etc/init.d/openresty restart
測試