Docker安装Nginx容器配置及重新生成镜像图文教程(docker启动nginx镜像)不看后悔

随心笔谈2年前发布 admin
194 0 0

文章摘要

这篇文章主要介绍了如何在Docker容器中配置Nginx服务器,包括以下核心内容: 1. 在Docker容器中使用`docker exec -it mynginx /bin/bash`运行Nginx服务。 2. 查看容器内的文件系统,包括配置目录和脚本。 3. 使用`whereis nginx`命令检查Nginx的安装路径。 4. 配置Nginx服务器,包括设置访问日志(`access_log`)、绑定地址(`server_name`)、静态页面目录(`root`)等。 5. 配置500错误页面(`error_page`)及其路由(`location`)。 6. 代理PHP脚本到FastCGI服务器,设置快照参数(`fastcgi_params`)。 7. 禁止访问.htaccess文件。 总结:文章详细讲解了在Docker容器中配置Nginx服务器的技术细节,适合需要在容器环境中部署静态网页服务器的用户参考。

C:\Users\Administrator>docker exec -it mynginx /bin/bash
root@1eb487ead85e:/# ls
bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var
boot docker-entrypoint.d etc lib media opt root sbin sys usr
root@1eb487ead85e:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@1eb487ead85e:/# cd /etc/nginx
root@1eb487ead85e:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
root@1eb487ead85e:/etc/nginx# cd conf.d
root@1eb487ead85e:/etc/nginx/conf.d# ls
default.conf
root@1eb487ead85e:/etc/nginx/conf.d# cat default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location=/50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}
root@1eb487ead85e:/etc/nginx/conf.d# cd /usr/share/nginx/html
root@1eb487ead85e:/usr/share/nginx/html# ls
50x.html index.html

© 版权声明

相关文章