The official Nginx mirror is used here and can be pulled using the following command:
Docker Pull Nginx
The main configuration of load balancing is in the following two files:
/etc/nginx/conf.d/default.conf:
server {Listen 80; server_name localhost;
#charset Koi8-r; #access_log/var/log/nginx/host.access.log Main;
Location/{
Proxy_set_header Host $host; Proxy_set_header X-real-ip $remote _addr; Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_buffering off;
#这里设置URL Proxy_pass Http://chenyufeng;
}
#error_page 404/404.html;
# REDIRECT Server error pages to the static page/50x.html # Error_page 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://12 7.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 ' one # #location ~/\.ht { # Deny All; #} }
/etc/nginx/nginx.conf:
User Nginx; Worker_processes 1;
Error_log/var/log/nginx/error.log warn; Pid/var/run/nginx.pid;
Note: Docker official Nginx mirroring may be slightly different from the nginx used in actual Linux, Nginx in Linux may not have CONF.D folders, all of which are in nginx.conf. But in the official image of Docker there is a conf.d directory in which default.conf is used to configure parameters such as server; Note: Upstream to use LAN IP or public network IP, can not use localhost or 127.0.0.1; The official mirror may not have vim and lsof installed. You can use the command "Apt-get update", "Apt-get install Vim", "Apt-get install lsof" for installation.
Operation steps: 1. First pull the official Nginx mirror.
Docker Pull Docker
2. Start using the following command line:
Docker run--name name1-it-d-P 80:80 Nginx/bin/bash
Enter the container:
Docker exec-it Name1/bin/bash
Start Nginx:
/usr/sbin/nginx
If you restart the container, you need to manually restart the nginx inside the container again, that is, execute "/usr/sbin/nginx" again. If you modify the configuration of the Nginx, it is recommended that you reboot the container and then manually restart the nginx inside the container again, which is to perform "/usr/sbin/nginx" again.
3. Directly in the browser can achieve load balancing http://localhost/co/docs/index.html
Any invocation of an interface is load balanced.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.