侧边栏壁纸
博主头像
伯淳的个人博客博主等级

行动起来,活在当下

  • 累计撰写 35 篇文章
  • 累计创建 5 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

用docker搭建LDNMP建站环境(新)

Administrator
2023-12-04 / 0 评论 / 0 点赞 / 138 阅读 / 7578 字

L:linux

D:docker

N:nginx

M:mysql

P:php

搭建环境:

- vps:racknerd

- 系统:debian 11

- 域名:edong.us

操作步骤:

1. 更新系统

apt update -y && apt upgrade -y && apt install -y curl wget sudo socat

2. 创建安装目录

mkdir -p /root/data/docker_data/web

cd web

mkdir html

mkdir mysql

mkdir certs

touch nginx.conf

3. 配置docker-compose

vim docker-compose.yml

复制内容:

version: '3.8'

services:
  nginx:
    image: nginx
    container_name: nginx
    restart: always
    ports:
      - 80:80
      - 443:443      
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./certs:/etc/nginx/certs      
      - ./html:/var/www/html

  php:
    image: php:7.4-fpm
    container_name: php
    restart: always
    volumes:
      - ./html:/var/www/html

  mysql:
    image: mysql:5.7
    container_name: mysql
    restart: always
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=dbc961020
      - MYSQL_DATABASE=web
      - MYSQL_USER=web
      - MYSQL_PASSWORD=dbc961020

数据库名web和密码dbc961020是等会wordpress初始化要用到的。

4. 申请证书

curl https://get.acme.sh | sh

~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com

~/.acme.sh/acme.sh --issue -d 网站域名 --standalone

网站域名改为自己的域名

5. 下载证书

~/.acme.sh/acme.sh --installcert -d 网站域名 --key-file /root/data/docker_data/web/certs/key.pem --fullchain-file /root/data/docker_data/web/certs/cert.pem

/root/data/docker\_data是我放置web文件夹的路径。

6. nginx配置

events {
    worker_connections 1024;
}

http {

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
    
    client_max_body_size 1000m;  
    #上传限制参数1G以内文件可上传


# HTTP server
server {
    listen 80;
    server_name 网站域名;

    # Redirect all HTTP requests to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS server
server {
    listen 443 ssl;
    server_name 网站域名;

    http2 on;
        
    ssl_certificate /etc/nginx/certs/cert.pem;
    ssl_certificate_key /etc/nginx/certs/key.pem;

    root /var/www/html;
    index index.php;

    # rewrite ^/vip.php(.*)$ /vip.php?s=$1 last;
        
    try_files $uri $uri/ =404;
    
    # PHP-FPM configuration
    location ~ \.php$ {
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

}

7. 下载wordpress

cd /root/data/docker_data/web && wget https://cn.wordpress.org/latest-zh_CN.zip && sudo apt-get install -y unzip && unzip latest-zh_CN.zip -d html && rm latest-zh_CN.zip && mv /root/data/docker_data/web/html/wordpress/* /root/data/docker_data/web/html/

上述一键命令完成了下载,解压,以及把wordpress文件的内容移到html下。

8. 启动容器

cd /root/data/docker_data/web && docker compose up -d

9.赋予权限

docker exec -it nginx chmod -R 777 /var/www/html

docker exec -it php chmod -R 777 /var/www/html

10. 安装PHP扩展

docker exec php apt update && docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev libmagickwand-dev imagemagick

docker exec php docker-php-ext-install mysqli pdo_mysql zip exif gd intl bcmath opcache

docker exec php pecl install imagick && docker exec php sh -c 'echo "extension=imagick.so" > /usr/local/etc/php/conf.d/imagick.ini'

执行完这个出现问题

解决:

docker exec -it php /bin/bash

cd /usr/local/etc/php

vim php.ini-development

添加下面的内容:

extension=imagick.so

#下面这条没有执行

docker exec -it php sh -c 'echo "upload_max_filesize=50M \n post_max_size=50M" > /usr/local/etc/php/conf.d/uploads.ini'

安装完成后重启php

docker restart php

## 11. 通过域名去访问网站

完成wp安装向导后再输入下面的命令!

跳过FTP更新主题插件的限制:

echo "define('FS_METHOD', 'direct');" >> /root/data/docker_data/web/html/wp-config.php

wordpress后台:网站域名/wp-admin/

改变

这次搭建的环境能够在wordpress中使用elementor插件了。

目前存在的问题

①无法把下载好的elementor插件zip文件上传并下载,只能在wordpress中搜索elementor下载。

②(已解决)

如果选中这个,则我的文章和关于页面打开都有问题。其实这就是没有设置伪静态的问题。

解决方案:我直接把nginx.conf配置文件发给gpt

更新后的nginx.conf文件如下:

events {
    worker_connections 1024;
}

http {

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
    
    client_max_body_size 1000m;  
    #上传限制参数1G以内文件可上传


# HTTP server
server {
    listen 80;
    server_name edong.us;

    # Redirect all HTTP requests to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS server
server {
    listen 443 ssl;
    server_name edong.us;

    http2 on;
        
    ssl_certificate /etc/nginx/certs/cert.pem;
    ssl_certificate_key /etc/nginx/certs/key.pem;

    root /var/www/html;
    index index.php;

   # rewrite ^/vip.php(.*)$ /vip.php?s=$1 last;
        
   # try_files $uri $uri/ =404;#把这行注释
    location / {
        try_files $uri $uri/ /index.php?$args;
}

    location /wp-admin {
        try_files $uri $uri/ /index.php?$args;
}

 
    # PHP-FPM configuration
    location ~ \.php$ {
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

}

0

评论区