docker安装Openresty

简单版本命令:

docker run -d --name openresty -p 8080:80 openresty/openresty:1.15.8.2-7-centos

进入容器内

默认配置文件位置:

/etc/nginx/conf.d/default.conf

完整配置文件位置:

/usr/local/openresty/nginx/conf/nginx.conf

nginx.conf 的内容如下:

#
# This file is installed to:
#   `/usr/local/openresty/nginx/conf/nginx.conf`
# and is the file loaded by nginx at startup,
# unless the user specifies otherwise.
#
# It tracks the upstream OpenResty's `nginx.conf`, but removes the `server`
# section and adds this directive:
#     `include /etc/nginx/conf.d/*.conf;`
#
# The `docker-openresty` file `nginx.vh.default.conf` is copied to
# `/etc/nginx/conf.d/default.conf`.  It contains the `server section
# of the upstream `nginx.conf`.
#
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-                                                                                                                              config-files
#

#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;

    # See Move default writable paths to a dedicated directory (#119)
    # https://github.com/openresty/docker-openresty/issues/119
    client_body_temp_path /var/run/openresty/nginx-client-body;
    proxy_temp_path       /var/run/openresty/nginx-proxy;
    fastcgi_temp_path     /var/run/openresty/nginx-fastcgi;
    uwsgi_temp_path       /var/run/openresty/nginx-uwsgi;
    scgi_temp_path        /var/run/openresty/nginx-scgi;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

可以将容器内的default.conf 文件拷贝到宿主机上,方便后续修改配置文件。

docker cp 5ee5c58996bc:/etc/nginx/conf.d/default.conf /data/openresty/conf.d/default.conf

这时可以将之前的openresty容器停止 并删除。 重新启动(升级版),命令如下:

docker run -d --name openresty -p 8080:80 -v /data/openresty/conf.d/:/etc/nginx/conf.d/ openresty/openresty:1.15.8.2-7-centos

如果还需要挂载宿主机上的文件资源如图片,可以使用下面命令:

docker run -d --name openresty -p 8080:80 -v /data/openresty/conf.d/:/etc/nginx/conf.d/ -v /tmp/webroot/shared1/:/tmp/webroot/shared1/ openresty/openresty:1.15.8.2-7-centos

需要在default.conf中配置访问路径和目录映射

location /shared1/ {
        alias  /tmp/webroot/shared1/;
        autoindex  on;
    }

参考:使用 OpenResty Docker 镜像快速搭建 Web 服务器 - 简书

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值