docker pull nginx
and put the files here. Map the directory corresponding to Nginx in docker without changing it. The file has entered the container
mkdir -p /data/nginx/{conf,conf.d,html,logs}
If it is inconvenient, you can open two windows and enter one Go to the container, copy the left side to the right side, this is to ensure that the file is correct
#启动容器 docker run -itd nginx /bin/bash #进入容器 docker attach xxxxxxxxxx
Instructions | File | Mounting path | nginx path |
nginx.conf | /data/nginx/conf/nginx.conf | /etc/nginx/nginx.conf | |
conf.d folder | /data/nginx/conf. d | /etc/nginx/conf.d | |
html folder | /data/nginx/ html | /usr/share/nginx/html | |
log folder | /data/nginx/logs | /var/log/nginx |
server { #端口号 listen 80; #定义使用 localhost 访问 server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { #根目录位置 root /usr/share/nginx/html; #index 文件位置 index 1.html; } #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; #} }
<html> <head> <title>Mynginx</title> </head> <body> <h2> 欢迎使用nginx! </h2> </body> </html>
docker run --name myNginx -d -p 8089:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/conf.d:/etc/nginx/conf.d -v /data/nginx/logs:/var/log/nginx nginx
docker ps
#进入容器 docker exec -it xxxxxxxxxxx /bin/bash #测试配置文件是否有问题 nginx -t #要是显示 successful 就可以更新了 nginx -s reload
The above is the detailed content of How to deploy Nginx on Docker. For more information, please follow other related articles on the PHP Chinese website!