Docker完整建站详介

一,在主服务器上操作:安装完成docker;略

二,查看镜像

[root@localhost ~]#docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos/shop2.web.top latest 8fc9b211671a 14 minutes ago 1.835 GB .....

三,运行镜像及在镜像内安装nginx环境

1,docker run -it -p 10888:8888 -p 10222:22 -p 8081:80 --name centos/shop2.web.top

2,如果使用-d后台参数,就使用docker exec -it ..., 进入docker.

#/etc/init.d/php-fpm-54 start #/etc/init.d/sshd start [不能使用winscp,进入了ssh] #/etc/init.d/bt start [启动它,才能访问80]

3,配置宝塔nginx,不要安装mysql。因为mysql经常有数据变动,并且安装docker mysql镜像很麻烦。请在docker外的服务器安装mysql即可。

4,docker内的shop2的配置:

登录到http://103.15.104.*:10888/login 到宝塔内面,或进入容器内docker exec -it [容器id] /bin/bash。进行配置

5,nginx配置文件:

# 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,在容器内配置好nginx,然后nginx reload.访问站点

[root@8825f8263497 /]# curl http://127.0.0.1:8082 【结果正确,省。。。】

四 主服务器配置环境及访问站点:

1,#cd /usr/local/tengine2/conf/ 【我使用的是tengine]

2, 将下面的配置加到nginx.conf文件内

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,重启nginx

#ps -ef | grep nginx root 18687 1 0 Feb21 ? 00:00:00 nginx: master process ./nginx

#kill -9 18687

#./sbin/nginx

说明:如果使用killall nginx ,会将docker容器内的nginx也kill掉。

4,完成。 # curl http://web.top [经测试成功]

备注: 1,查看容器的ip

docker inspect --format='{{.NetworkSettings.IPAddress}}' $(docker ps -a -q) 2,查看容器的name

sudo docker inspect -f='{{.Name}}' $(sudo docker ps -a -q)

转载于:https://my.oschina.net/7795442/blog/1622961

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值