smilesundream的博客

开心就好

openresty安装

教程

注:配置过程中在执行如图第6步时按

listen       192.168.0.100:8080;
listen       192.168.0.100:8443 ssl;

显示绑定失败,最后将前面额ip改成localhost,如下所示:

http {
     18     include       mime.types;
     19     default_type  application/octet-stream;
     20 
     21     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
     22     #                  '$status $body_bytes_sent "$http_referer" '
     23     #                  '"$http_user_agent" "$http_x_forwarded_for"';
     24 
     25     #access_log  logs/access.log  main;
     26 
     27     sendfile        on;
     28     #tcp_nopush     on;
     29 
     30     #keepalive_timeout  0;
     31     keepalive_timeout  65;
     32 
     33     #gzip  on;
     34 lua_package_path '/usr/local/openresty/lualib/?.lua;/usr/local/openresty/nginx/lua/?.lua;;';//记得添加这两个模块
     35 lua_package_cpath '/usr/local/openresty/lualib/?.so;;';
     36 
     37     server {
            listen      localhost:8001;
     39     listen       localhost:8443 ssl;
     40     server_name  localhost;
     41 
     42     ssl_certificate /usr/local/openresty/nginx/cert/server.crt;
     43     ssl_certificate_key /usr/local/openresty/nginx/cert/server.key;
     44 
     45         #charset koi8-r;
     46 
     47         #access_log  logs/host.access.log  main;
     48 
     49         location / {
     50             root   html;
     51             index  index.html index.htm;
     52         }

附原文——————————————————————————————————————————————————————

安装环境:CentOS 7.0

1、 安装编译工具、依赖库

yum -y install readline-devel pcre-devel openssl-devel gcc
  • 1

2、 下载openresty-1.13.6.1.tar.gz 源码包,并解压;下载ngx_cache_purge模块,该模块用于清理nginx缓存;下载nginx_upstream_check_module模块,该模块用于ustream健康检查

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

3、配置需安装的模块

# ./configure --help可查询需要安装的模块
./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/
  • 1
  • 2
  • 3

4、编译安装

# you can change the parallism number 2 below to fit the number of spare CPU cores in your machine.
make -j2 && make install
  • 1
  • 2

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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.0.100:8080;
    listen       192.168.0.100:8443 ssl;
    server_name  localhost;

    ssl_certificate /usr/local/openresty/nginx/cert/server.crt;
    ssl_certificate_key /usr/local/openresty/nginx/cert/server.key;
    ...
    ...
    ...
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

7、启动Nginx服务,查看进程及连接情况

/usr/local/openresty/nginx/sbin/nginx
ps -ef | grep nginx
netstat -ltpe | grep nginx
  • 1
  • 2
  • 3

8、访问测试Nginx

curl -k https://192.168.0.100:8443
curl -i http://192.168.0.100:8080
  • 1
  • 2

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

#systemctl start nginx.service
systemctl enable nginx.service
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld


——————————————————————————————————————————————————


以上安装成功,下面是测试demo:

链接

注: 按 nginx -p ~/openresty-test 提示错误,后来将后面的路径改为绝对路径才成功

/usr/local/openresty/nginx/sbin/nginx  -p /home/oupeng/openresty-test

      1 worker_processes  1;
      2 error_log logs/error.log;
      3 events {
      4     worker_connections 1024;
      5 }   
      6 http {
      7     server {
      8         listen 8080;
      9         location / {
     10             default_type text/html;
     11             content_by_lua '
     12                 ngx.say("<p>oupeng ,you can do it</p>")
     13             ';  
     14         }   
     15     }   
     16 }   




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/smilesundream/article/details/80343121
个人分类: Openresty
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

openresty安装

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭