Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文档完善-使用Docker-Compose搭建-LNMP反向代理 #256

Closed
eezd opened this issue Aug 20, 2021 · 1 comment
Closed

文档完善-使用Docker-Compose搭建-LNMP反向代理 #256

eezd opened this issue Aug 20, 2021 · 1 comment
Labels
good first issue Good for newcomers

Comments

@eezd
Copy link

eezd commented Aug 20, 2021

lskypro-dockerCompose-php7.3apache

已支持 2.0 Docker,

1、思路

用Docker-Compose构建mysql+lskypro,然后用LNMP反向代理到域名。

2、拉取镜像

首先感谢这位大哥的Dockerfile文件

要注意他的Dockerdile文件还没修改PHP上传图片的限制,我在他基础上修改成100M,待会会对此进行说明。

镜像包:https://hub.docker.com/repository/docker/zyugat/lskypro

docker pull zyugat/lskypro:1.6.3

构建文件:https://github.com/zyugat/lsky-DockerCompose-php7.3apache

3、构建文件

./mysql/init:初始化数据库

CREATE DATABASE IF NOT EXISTS lsky DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

docker-compose.yaml

# yml文件
version: '3'
services:
  mysql-main:
    image: mysql:5.7.22
    restart: always
    #名称(可以为空)
    hostname: mysql-main
    #容器名称
    container_name: mysql-main 
    # 修改加密规则
    command: --default-authentication-plugin=mysql_native_password
    ports: 
    - "9306:3306" 
    volumes:
      - mysql-data:/var/lib/mysql
      - mysql-conf:/etc/mysql
      - mysql-log:/var/log/mysql
      - ./mysql/init:/docker-entrypoint-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: mysqlpsw
    networks:
      - mysql-net
    
  lskypro:
    # build:
    #   # 指定dockerfile文件的所在路径
    #   context: ./lskypro
    #   # 指定Dockerfile文件名称
    #   dockerfile: Dockerfile
    image: zyugat/lskypro:1.6.3
    restart: always
    hostname: lskypro
    container_name: lskypro
    ports: 
      - "9080:80" 
    volumes:
      - lsky-data:/var/www/html
    networks:
      - mysql-net

volumes:
  mysql-data:
  mysql-conf:
  mysql-log:
  lsky-data:

networks:
  mysql-net:

补充:docker-php-upload.ini=>/usr/local/etc/php/conf.d/docker-php-upload.ini

PHP上默认会限制10M,需要修改。

post_max_size = 100M;
upload_max_filesize = 100M;
max_execution_time = 600S;

4、运行

进入目录,我的是:cd /home/docker

运行:docker-compose up -d

测试:IP:9080

如果能打开就说明,你已经成功一半了,如果无法访问,检查防火墙有没有开启9080端口

5、配置lnmp反向代理

添加虚拟主机:lnmp vhost add

自己添加,这里不做多说明。

添加完后,编辑文件:vim /usr/local/nginx/conf/vhost/你的域名.conf,在server里添加:

        location / {
            proxy_pass http://127.0.0.1:9080;
            index  index.html index.htm index.jsp;
        }

文件上传限制大小

vim /usr/local/nginx/conf/nginx.conf

修改:client_max_body_size

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 100m;	#  修改这个!!

重载配置:/etc/init.d/nginx reload

防跨目录设置

参考:#31

cd /opt/lnmp1.x/tools
./remove_open_basedir_restriction.sh

你可能会遇到的问题:

使用域名访问的时候报错,无法找到static目录,同时一直在转圈,无法保存配置。

GET https://域名/static/app/iconfont/iconfont.css net::ERR_ABORTED 404
GET https://域名/static/app/css/app.css?v=1.5 404
GET https://域名/static/app/css/markdown.css?v=1.0 net::ERR_ABORTED 404
...

解决办法:

编辑文件:vim /usr/local/nginx/conf/vhost/你的域名.conf

将以下内容全部注释,即可。

        # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        # {
        #     expires      30d;
        # }

        # location ~ .*\.(js|css)?$
        # {
        #     expires      12h;
        # }

        # location ~ /.well-known {
        #     allow all;
        # }

        # location ~ /\.
        # {
        #     deny all;
        # }

6、获取连接数据库的地址

查询方式:docker network inspect docker_mysql-net

连接数据库地址:172.19.0.1

7、参考网址

镜像包:https://hub.docker.com/repository/docker/zyugat/lskypro

构建文件:https://github.com/zyugat/lsky-DockerCompose-php7.3apache

https://github.com/Handsomedoggy/lsky-pro

https://lnmp.org/faq/lnmp-vhost-add-howto.html#user.ini

#31

https://laosu.ml/2021/07/02/%E5%BC%80%E6%BA%90%E7%9A%84%E5%85%B0%E7%A9%BA%E5%9B%BE%E5%BA%8ALskyPro/?highlight=lsky

@0xxb 0xxb added the good first issue Good for newcomers label Aug 23, 2021
@eezd
Copy link
Author

eezd commented Aug 26, 2021

迁移数据方法:

备份docker-compose文件:tar -czvf docker.tar.gz /home/docker

备份volumes文件:tar -czvf volumes.tar.gz /var/lib/docker/volumes

将备份文件拷贝到迁移机器,进行解压

tar -xzvf docker.tar.gz -C /home/docker
tar -xzvf volumes.tar.gz -C /var/lib/docker/volumes

创建网络:docker network create mysql-net

查看网络IP:docker network inspect mysql-net

数据库IP是:172.19.0.1

IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.19.0.0/16",
                    "Gateway": "172.19.0.1"
                }
            ]
        },

修改数据库连接地址(IP)填写:vim volumes/lsky-data/_data/.env

运行:docker-compose up -d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants