1. Download the Nginx image from docker
docker pull nginx
2. Create the mounting directory
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}
3. In order to ensure the correctness of the file, it is recommended to enter the container first and copy the corresponding file.
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; #} }The 1.html used for testing here is written by myself
<html> <head> <title>Mynginx</title> </head> <body> <h2> 欢迎使用nginx! </h2> </body> </html>5. Next, you can start the container
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
The mounting path must be correct, don’t write Wrong-p 8089:80 Here, map port 80 to port 8089 of the host, so that the access is port 8089. There is no need to change the default port of nginxYou can take a look next Whether the container starts normallydocker psIf you don’t see the container, it means there is a problem with the startup. Check whether the configuration file is written incorrectly or the mounting path is incorrect.You can directly start it after starting it. Browser localhost:8089 I saw the 1.index page I just wrote6. Update the configuration file without stopping nginxWhen we modify the configuration file, we need to update the configuration file. At this time, open two The window is very cool
#进入容器 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!

NGINX improves performance through its event-driven architecture and asynchronous processing capabilities, enhances scalability through modular design and flexible configuration, and improves security through SSL/TLS encryption and request rate limiting.

NGINX is suitable for high concurrency and low resource consumption scenarios, while Apache is suitable for scenarios that require complex configurations and functional extensions. 1.NGINX is known for handling large numbers of concurrent connections with high performance. 2. Apache is known for its stability and rich module support. When choosing, it must be decided based on specific needs.

NGINXisessentialformodernwebapplicationsduetoitsrolesasareverseproxy,loadbalancer,andwebserver,offeringhighperformanceandscalability.1)Itactsasareverseproxy,enhancingsecurityandperformancebycachingandloadbalancing.2)NGINXsupportsvariousloadbalancingm

To ensure website security through Nginx, the following steps are required: 1. Create a basic configuration, specify the SSL certificate and private key; 2. Optimize the configuration, enable HTTP/2 and OCSPStapling; 3. Debug common errors, such as certificate path and encryption suite issues; 4. Application performance optimization suggestions, such as using Let'sEncrypt and session multiplexing.

Nginx is a high-performance HTTP and reverse proxy server that is good at handling high concurrent connections. 1) Basic configuration: listen to the port and provide static file services. 2) Advanced configuration: implement reverse proxy and load balancing. 3) Debugging skills: Check the error log and test the configuration file. 4) Performance optimization: Enable Gzip compression and adjust cache policies.

Nginx cache can significantly improve website performance through the following steps: 1) Define the cache area and set the cache path; 2) Configure the cache validity period; 3) Set different cache policies according to different content; 4) Optimize cache storage and load balancing; 5) Monitor and debug cache effects. Through these methods, Nginx cache can reduce back-end server pressure, improve response speed and user experience.

Using DockerCompose can simplify the deployment and management of Nginx, and scaling through DockerSwarm or Kubernetes is a common practice. 1) Use DockerCompose to define and run Nginx containers, 2) implement cluster management and automatic scaling through DockerSwarm or Kubernetes.

The advanced configuration of Nginx can be implemented through server blocks and reverse proxy: 1. Server blocks allow multiple websites to be run in one instance, each block is configured independently. 2. The reverse proxy forwards the request to the backend server to realize load balancing and cache acceleration.


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

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft