preface

The previous article introduced docker+ Jenkins to build front-end continuous integration tools, and finally uploaded the files below dist to the directory /home/www/webpre through sshServers. Here is how to configure nginx to access packaged static files.

Download nginx

Execute dockers pull nginx

 dockers pull nginx

Copy the code

Download and view the docker installation image

docker images

Copy the code

Nginx has been downloaded.

Map nginx configuration files to /home/docker-nginx folder

docker run --name nginx -p 80:80 -v /home/docker-nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/www:/home/www -v /home/docker-nginx/log:/var/log/nginx -v /home/docker-nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /home/docker-nginx/html:/usr/share/nginx/html -d nginx

Copy the code

–name Specifies a name for the container you started. You can use this name to start or stop the container later

-p mapping port binds port 80 of the Docker host to port 80 of the container

-v is used to mount files. The first -v means overwriting your local nginx.conf file to the container you want to start

-d indicates the mirror to be started.

Docker :nginx/home/docker-nginx/

docker exec-it nginx bash // enter docker:nginx

exit/ / exit

Docker cp docker: nginx/usr/share/nginx/HTML/home/docker nginx/HTML copy nginx nginx/usr/share/nginx/HTML File to host /home/docker-nginx/ HTML

Copy the code

Then go to http://ip:80Stop nginx, modify /home/docker-nginx/ HTML /index.html, start again, access again, verify that the configuration is successful

Docker stop nginx // Stop nginx service

Docer start nginx

Docker remove nginx // delete container

Docker ps // View the running container

Docker ps -a // View all containers

Copy the code

Modify the nginx configuration file

Need to modify the/home/docker – nginx/conf. D/default. Conf/home/docker – nginx/nginx. Conf

Vi/home/docker - nginx/conf. D/default. Conf / / open the file

A / / modify

ESC + : + w + q // Exit and save the file

+ w + w // Exit without saving the file

Copy the code

server_name => localhost

Root => Default access HTTP: IP :80 root directory: host host /home/www

Index => Default file to access

For other configurations, please search baidu by yourself

After the configuration is complete, restart the nginx service and visit http://ip:80/webpre to see your packaged page.

At the end

Above is a simple Docker +nginx configuration static server. Docker-compose: Docker-compose: docker-compose: docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose Pay attention to me!!!!!!! The next article is revealed.