First, operate on the main server: the installation is complete docker; slightly
Second, view the mirror
[root@localhost ~]#docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos/shop2.web.top latest 8fc9b211671a 14 minutes ago 1.835 GB .....
Third, run the mirror and install the nginx environment in the mirror
1,docker run -it -p 10888:8888 -p 10222:22 -p 8081:80 --name centos/shop2.web.top
2. If you use the -d background parameter, use docker exec -it ... to enter docker.
#/etc/init.d/php-fpm-54 start #/etc/init.d/sshd start [Cannot use winscp, enter ssh] #/etc/init.d/bt start [Start it to access 80 ]
3, configure the pagoda nginx, do not install mysql. Because mysql often has data changes, and installing the docker mysql image is very troublesome. Please install mysql on the server outside docker.
4, the configuration of shop2 in docker:
Log in to http://103.15.104.*:10888/login to the inside of the pagoda, or enter the container and docker exec -it [container id] /bin/bash. configure
5, nginx configuration file:
# vi /www/server/nginx/conf/nginx.conf
[root@8825f8263497 /]# cat /www/server/nginx/conf/nginx.conf
user www www;
worker_processes auto;
error_log /www/wwwlogs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
include proxy.conf;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server
{
listen 888;
server_name www.bt.cn;
index index.html index.htm index.php;
root /www/server/phpmyadmin;
#error_page 404 /404.html;
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /www/wwwlogs/access.log;
}
server
{
listen 8082;
server_name 127.0.0.1; #这个很重要,主要在docker的容器外访问http://172.17.0.4:80可以访问。
index index.html index.htm index.php;
root /www/wwwroot/shop;
#error_page 404 /404.html;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ .php($|/) {
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi-54.sock;
fastcgi_index index.php;
include fastcgi.conf;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /www/wwwlogs/access.log;
}
include /www/server/panel/vhost/nginx/*.conf;
}
4. Configure nginx in the container, and then nginx reload. Access the site
[root@8825f8263497 /]# curl http://127.0.0.1:8082 [The result is correct, save. . . 】
Four main server configuration environment and access site:
1, #cd /usr/local/tengine2/conf/ [I am using tengine]
2, Add the following configuration to the nginx.conf file
server {
listen 80;
server_name web.top;
error_log logs/shop2.web.log;
location / { 【关键是这个代理,将请求的web.top:80的协议转到web.top】
proxy_buffering off;
proxy_pass http://172.17.0.4:8082; 【172.17.0.4 是容器的ip地址】
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
3, restart nginx
#ps -ef | grep nginx root 18687 1 0 Feb21 ? 00:00:00 nginx: master process ./nginx
#kill -9 18687
#./sbin/nginx
Note: If you use killall nginx, the nginx in the docker container will also be killed.
4. Done. # curl http://web.top [tested successfully]
Remarks: 1. View the ip of the container
docker inspect --format='{{.NetworkSettings.IPAddress}}' $(docker ps -a -q) 2, view the name of the container
sudo docker inspect -f='{{.Name}}' $(sudo docker ps -a -q)