docker 安装 openresty
Posted 杰哥的技术杂货铺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker 安装 openresty相关的知识,希望对你有一定的参考价值。
- openresty-github:https://github.com/openresty/openresty
- openresty中文邮件帮助:https://groups.google.com/group/openresty
- openresty-docker:https://github.com/openresty/docker-openresty
- openresty-dockerhub:https://hub.docker.com/r/openresty/openresty/dockerfile
了解过web服务器的朋友肯定对nginx不陌生,nginx作为目前占有率第一的web服务器,本身作为静态web服务器、反向代理服务和四层、七层负载均衡器都有着非常优秀的表现。但是对于web服务器而言,nginx的很多功能都偏向于静态web应用,也就是说它的动态处理能力是有一定的缺失的。举个最简单的例子,nginx无法在配置中直接进行一个条件以上的逻辑判断,这对于一些架构设计来说有着较大的不便。OpenResty的诞生就是为了解决这个问题。
1、下载openresty镜像
docker pull openresty/openresty:1.19.3.1-alpine
2、新建openresty挂载目录:
mkdir -p /opt/docker/openresty/conf.d,html,logs,cert
3、编写openresty容器启动脚本
# vim /opt/docker/openresty/run.sh
#!/bin/bash
docker run -itd --restart=unless-stopped \\
--network=host \\
--name openresty \\
-v /opt/docker/openresty/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf \\
-v /opt/docker/openresty/conf.d:/etc/nginx/conf.d \\
-v /opt/docker/openresty/logs:/usr/local/openresty/nginx/logs \\
-v /opt/docker/openresty/html:/usr/local/openresty/nginx/html \\
-v /opt/docker/openresty/cert:/usr/local/openresty/nginx/cert \\
-v /opt/docker/openresty/run:/var/run/openresty \\
-v /opt/docker/openresty/nginx/lua:/usr/local/openresty/nginx/lua \\
openresty/openresty:1.19.3.1-alpine
docker logs -f openresty
4、编写建openresty-nginx主配置文件
# vim /opt/docker/openresty/nginx.conf
worker_processes 4;
#user nginx;
events
worker_connections 409600;
http
include mime.types;
default_type application/octet-stream;
server_tokens off;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
keepalive_timeout 65;
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 /usr/local/openresty/nginx/logs/access.log main;
error_log /usr/local/openresty/nginx/logs/error.log error;
include /etc/nginx/conf.d/*.conf;
5、编写openresty虚拟主机配置文件
- https域名conf文件配置
# vim openresty-443.conf
server
listen 80;
server_name 127.0.0.1;
rewrite ^ https://$http_host$request_uri? permanent;
server_tokens off;
server
listen 443 ssl;
server_name 127.0.0.1;
ssl_certificate /usr/local/openresty/nginx/cert/xxx.com.pem;
ssl_certificate_key /usr/local/openresty/nginx/cert/xxx.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
charset utf-8;
location /
root /usr/local/openresty/nginx/html;
index index.php index.html index.htm;
access_log /usr/local/openresty/nginx/logs/access.log main;
- http域名conf文件配置
# vim openresty.template.conf
server
listen 80;
server_name 127.0.0.1;
charset utf-8;
location /
root /usr/local/openresty/nginx/html;
index index.php index.html index.htm;
access_log /usr/local/openresty/nginx/logs/access.log main;
- 反向代理配置
server
listen 80;
server_name 127.0.0.1;
location /
proxy_redirect off;
proxy_pass http://0.0.0.0/;
access_log /usr/local/openresty/nginx/logs/access.log main;
以上是关于docker 安装 openresty的主要内容,如果未能解决你的问题,请参考以下文章
使用 OpenResty Docker 镜像快速搭建 Web 服务器
使用lua graphql 模块让openresty 支持graphql api