docker安装与运行nginx并将端口映射到443
安装nginxdocker pull nginx创建并启动容器# /usr/share/nginx/html:部署网站的根目录# /etc/nginx/nginx.conf:nginx配置文件# /etc/nginx/cert:证书存放目录docker run -p 443:443 --name nginx443 -v /usr/local/docker/nginx443/html:/usr/sh
·
安装nginx
docker pull nginx
创建并启动容器
# /usr/share/nginx/html:部署网站的根目录
# /etc/nginx/nginx.conf:nginx配置文件
# /etc/nginx/cert:证书存放目录
docker run -p 443:443 --name nginx443 -v /usr/local/docker/nginx443/html:/usr/share/nginx/html -v /usr/local/docker/nginx443/logs:/var/log/nginx -v /usr/local/docker/nginx443/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/docker/nginx443/conf/cert:/etc/nginx/cert -v /etc/localtime:/etc/localtime -d nginx
删除/usr/local/docker/nginx443/conf/nginx.conf文件夹,创建一个nginx.conf配置文件,内容如下:
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
ssl on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_certificate /etc/nginx/cert/www.xxx.com.pem; #证书路径
ssl_certificate_key /etc/nginx/cert/www.xxx.com.key; #请求认证 key 的路径
server {
listen 443; #监听端口,ssl默认443端口。如果需要配置多个端口,可以继续添加server,用不同的端口就行
server_name www.xxx.com; #服务器域名,需要和申请的证书匹配
location / {
root /usr/share/nginx/html; #网站根目录,和容器创建时指定的位置一致
index index.html index.htm;
}
}
}
重启nginx容器
docker restart nginx443
至此配置完成,可以在/usr/local/docker/nginx443/html目录下创建一个index.html,随便写一个内容,访问一下是否成功即可
更多推荐
已为社区贡献3条内容
所有评论(0)