First, the structure inside the nginx container: Enter the container: docker exec -it b511b6049f57 bash View the container structure directory: In fact, each container is equivalent to an independent system. root@b511b6049f57:/# ls bin dev home lib64 mnt proc run srv tmp var boot etc lib media opt root sbin sys usr The structure directory of nginx is in the container:
If you want to add a location locally, you need to mount the configurations in these containers locally: The configuration file is relatively troublesome. Generally, nginx only needs to load nginx.conf. In dokcer, nginx.conf is loaded first, and then there is a line in nginx.conf including include /etc/nginx/conf.d/*.conf;, which loads the configuration file in the conf.d directory. So for the configuration, you only need to mount it to conf.d and overwrite it. Create the corresponding folder and main configuration file nginx.conf locally: mkdir -p /home/test/nginx/{log,conf,html} touch nginx.conf nginx.conf contains sub-configuration files (last line): user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '"$remote_addr" "$http_host" "[$time_local]" "$request" "$status" "$body_bytes_sent" ' '"$bytes_sent" "$gzip_ratio" "$http_referer" "$http_user_agent" "$http_x_forwarded_for" ' '"$upstream_addr" "$upstream_response_time" "$request_time" "$request_body" "$http_authorization" '; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } Create a default.conf under conf: server { listen 80; server_name localhost; #charset koi8-r; access_log /var/log/nginx/log/host.access.log main; location / { #root /data/nginx/html; root /usr/share/nginx/html; index index.html index.htm; #autoindex on; #try_files $uri /index/index/page.html; #try_files $uri /index/map/page.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; } location ~ /images { default_type application/json; return 200 '{"code": "A000000", "message": "ok", "timestamp": "20180307184426", "data": {"isvip": "1", "monthProList": []}}'; } # 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; #} } After preparing the above local files, start the container and mount it to the local related configuration files: docker run --name docker_nginx -d -p 80:80 \ -v /home/test/nginx/log:/var/log/nginx \ -v /home/test/nginx/conf:/etc/nginx/conf.d \ -v /home/test/nginx/nginx.conf:/etc/nginx/nginx.conf \ -v /home/test/nginx/html:/usr/share/nginx/html nginx ### The first -v: mount the log directory The second -v: mount the configuration directory The third -v: mount the main configuration file The fourth -v: mount the project directory After the mounting is complete, visit the main page: Then access the location /images we wrote in default before: Restart nginx: docker exec -it b511b6049f57 nginx -s reload This is the end of this article about starting and mounting the docker nginx container locally. For more relevant docker nginx startup and mounting content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: A brief introduction to MySQL storage engine
>>: JavaScript implements the most complete code analysis of a simple magnifying glass (ES5)
1. Use the <a> tag to complete <a href=&...
Mapping the mouse position or implementing drag e...
Here are 10 tips on how to design better-usable w...
Table of contents Single Node Diff reconcileSingl...
The most common way is to set a primary key or un...
MySQL official website download address: https://...
Table of contents 1. Pull the Redis image 2. Crea...
1. Please download the Busybox source code online...
Table of contents Introduction: Installation of e...
1. Installation Install using yum ##Automatically...
Table of contents Start Docker Stop Docker Python...
Empty link: That is, there is no link with a targ...
I encountered such a problem during development A...
WeChat applet's simple calculator is for your...
In this system, the # sign represents the root us...