Get it done with just one line of command:
docker run \ --name nginx-health-web-pc \ -d -p 6800:80 \ -v /usr/docker/nginx/html:/usr/share/nginx/html \ nginx
It’s a joy to run and start~~~~~At this time, the front end suddenly came over and said: "You need to add a configuration to your nginx", and by the way, he also told you: " "So-and-so was configured like this before",
You can't refuse if you are competitive at this time, but it still takes some effort to actually configure it. Under normal circumstances, docker is configured when it starts, as long as the configuration file Just mount the directory, which is simple and convenient. However, nginx first loads a main configuration file nginx.conf, and then loads the sub-configuration files in the conf.d directory in nginx.conf (usually at least one default.conf file). This is a lot more troublesome than mounting a directory alone, but it's not difficult as long as you have a clear idea.
Let’s look at the mounted command first:
Command to start docker
docker run \ --name mynginx \ -d -p 80:80 \ -v /usr/docker/mynginx/html:/usr/share/nginx/html \ -v /etc/docker/mynginx/nginx.conf:/etc/nginx/nginx.conf:ro \ -v /etc/docker/mynginx/conf.d:/etc/nginx/conf.d \ nginx
There are a few things to note here:
(1) The first "-v" is the project location, just put the project in the directory where it is mounted;
(2) The second "-v" is Mount the main configuration file "nginx.conf". Note that there is a line "include /etc/nginx/conf.d/*.conf;" in the "nginx.conf" file. This include points to the path of the sub-configuration file. This Please pay attention to the path following include and make sure there is no mistake.
(3) The third "-v" also mounts the path of the sub-configuration file in docker. Note that it must be consistent with the path pointed to by include in (2)
(4) It is important to emphasize that nginx.conf mounts a file (docker is not recommended to use this way), and conf.d mounts a directory.
Let’s start it first, and we can find that there is a problem. Because the configuration file does not exist yet.
Configuration configuration file
We find the configuration file generated when nginx is installed by the conventional method (usually under "/etc/nginx"), corresponding to the above startup command The mounting location, put the main configuration file nginx.conf into the corresponding location "/etc/docker/mynginx/nginx.conf", and put the sub-configuration file "default.conf" into "/etc/docker/mynginx/conf. d" directory
Re-run the startup command,found that it is ready. At this point, the files in docker can be configured at will, which is exactly the same as the native installation
Thinking: There must be one idea when configuring: the mounted file must be loaded into the docker process when running! This way there is less confusion.
-------------------------------------------------- -------Divider line------------------------------------------ --------------
Post my configuration file:
nginx.conf
user root; 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 - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; autoindex on; #gzip on; include /etc/nginx/conf.d/*.conf; client_max_body_size 100m; client_header_buffer_size 128k; large_client_header_buffers 4 128k; }
default.conf
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/nginx/dacheng-wechat-web; # root /usr/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; } # 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; #} }
The above is the detailed content of How Docker deploys nginx and modifies configuration files. For more information, please follow other related articles on the PHP Chinese website!

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

The server does not have permission to access the requested resource, resulting in a nginx 403 error. Solutions include: Check file permissions. Check the .htaccess configuration. Check nginx configuration. Configure SELinux permissions. Check the firewall rules. Troubleshoot other causes such as browser problems, server failures, or other possible errors.

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version