正文

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

文章摘要

这篇文章介绍了如何通过Docker容器配置Nginx服务器,主要涉及以下几个方面: 1. 使用`docker exec`命令进入Nginx容器并执行脚本,修改配置文件路径; 2. 设置Nginx服务器的服务器名称为`localhost`; 3. 配置服务器静态资源路径为`/usr/share/nginx/html`; 4. 设置默认访问日志路径; 5. 配置快照(FastCGI)参数,将PHP脚本转发到Apache服务器; 6. 禁用访问`.htaccess`文件等。 文章重点介绍了Nginx的配置方法,适合需要通过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