简单版本命令:
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;
}