openresty安装

centos:

yum -y install readline-devel pcre-devel openssl-devel

ubuntu:

apt-get install libreadline-dev libpcre3-dev libssl-dev perl
wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz   # 下载
tar xzvf ngx_openresty-1.9.7.1.tar.gz       # 解压
cd ngx_openresty-1.9.7.1/ 
./configure --prefix=/etc/nginx/nginx/sbin (nginx执行文件目录) --with-luajit --without-http_redis2_module --with-http_iconv_module
make 
make install 

相关配置项

./configure --sbin-path  // 设置nginx的二进制文件路径

--conf-path=  // 设置nginx配置文件路径

--with-openssl=  // 设置openssl路径(*注意 :是源码的地址)

--error-log-path=  // 设置错误日志(error日志)

--pid-path= // 设置nginx pid 文件

--user= // 设置nginx启动用户

--group= // 设置nginx启动用户组

--with-http_v2_module \ // 开启http2模块,(包括https,grpc等)

--with-http_ssl_module \

--with-http_gzip_static_module \

--with-http_realip_module \

--with-http_flv_module \

--with-pcre-jit \

--prefix=/Users/bigstick/soft \

--with-http_sub_module \

--with-http_gunzip_module \

--http-log-path=/Users/bigstick/soft/nginx/logs \

--modules-path=/Users/bigstick/soft/nginx/modules

编辑配置文件

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 9000;
        location / {
            default_type text/html;
            content_by_lua '
                ngx.say("<p>Hello, World!</p>")
            ';
        }
    }
}
/usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c conf/nginx.conf       # 默认情况下 openresty 安装在 /usr/local/openresty 目录中
  -p 指定我们的项目目录,
  -c 指定配置文件。

没有任何输出,说明启动成功
curl http://localhost:9000/
<p>Hello, World!</p>      # 证明服务正常
或者浏览器访问:http://ip:9000 ,看是结果是否为:Hello, World!

启动

openresty是nginx的luaJit的扩展,openresty的启动、停止、启动操作,实际执行nginx的操作就可以了。
启动:nginx -c
快速停止nginx:nginx -s stop
完整有序的停止nginx:nginx -s quit
修改配置后重新加载生效:nginx -s reload
重新打开日志文件:nginx -s reopen

重启

如何重启openresty?
修改了openresty中的配置以后,或者更新了lua脚本,那么如何重启nginx,以使用更新后的lua脚本或者配置呢?

nginx -s reload 不会清空shared_dict,但是会重建luaVM,所说主要是为了兼容windows系统而保留的,不推荐使用。
kill -HUP cat /usr/local/openresty/nginx/logs/nginx.pid 和以上相比,不会重建luaVM

问题

nginx和openresty配置静态资源时,样式错乱,页面没有报错,查看css,作为静态文件已经加载了,但是不起作用。

原因

CSS加载过程,发现CSS加载时Content Type为“text/plain",不是”text/css“,所以才想起是MIME type的问题。

解决

nginx.conf中添加include mime.types;问题解决。

Openresty中不会加载默认的mime.types,需要自己手动添加,

Openresty中的mime.types文件所在位置openresty-1.15.8.2/build/nginx-1.15.8/conf/mime.types。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值