environment
Install Install Docker dependencies $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2 Install docker-ce $ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo $ sudo yum install docker-ce $ sudo systemctl start docker $ docker --version $ sudo docker run hello-world Install docker-compose $ sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose $ sudo chmod +x /usr/bin/docker-compose $ docker-compose --version Write docker-compose.yml $ mkdir ./blog $ cd blog $ sudo vim docker-compose.yml version: '3' services: db: image:mysql:5.7 volumes: #Data volume, mapping local folder - db_data:/var/lib/mysql ports: # If you don't write port mapping, the outside world cannot connect to the mysql (WordPress connection below is fine) - "3306:3306" restart: always environment: MYSQL_ROOT_PASSWORD: xxx MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: #Depends on the db service above -db image: wordpress:latest volumes: - wp_site:/var/www/html ports: - "8000:80" restart: always privileged: true environment: # You can directly use the above service name + port to get the link WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress # Define domain name WORDPRESS_CONFIG_EXTRA: "define('WP_HOME','https://blog.amoyiki.com'); define('WP_SITEURL','https://blog.amoyiki.com');" volumes: db_data: wp_site: Running the container # Start $ sudo docker-compose up -d # Shutdown$ sudo docker-compose down Now you can access it using http://ip:port. If you find that you cannot access it, you can check the container log to find errors. $ sudo docker-compose ps Name Command State Ports blog_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp, 33060/tcp blog_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:8000->80/tcp # The WordPress at the end is the name of the service. This is different from the container name used to view logs in Docker. $ sudo docker-compose logs -f --tail=10 wordpress $ sudo docker-compose logs -f --tail=10 db Use host Nginx to reverse docker wordpress The configuration file of nginx is as follows (irrelevant content omitted) user root; # This is because the WordPress file user in the docker container is www-data server { listen 80; server_name *.amoyiki.com; return 301 https://$host$request_uri; } upstream wordpress-workhorse { server 127.0.0.1:8000 fail_timeout=10s; } server { server_name blog.amoyiki.com; listen 443 ssl; ssl on; ssl_certificate /ssl/path/fullchain.pem; ssl_certificate_key /ssl/path/privkey.pem; access_log /var/log/nginx/access.log main; # WordPress data volume location in the host root /var/lib/docker/volumes/blog_wp_site/_data; location / { proxy_pass http://wordpress-workhorse; 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_set_header X-Forwarded-Proto https; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires 7d; access_log off; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } Error Collection nginx error Permission denied
Previously, my nginx.conf user used the default nobody, which could not read the user group data of www-data in wp in docker, so I directly promoted the nginx user to root, which can be optimized later. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to use type enhancement without typingscript
>>: mysql 5.7.11 winx64 initial password change
Let’s look at the effect first: This effect looks...
Preface In most projects, you will encounter onli...
Table of contents 1. Install JDK 2. Install Jenki...
Overview of Alibaba Cloud Security Group Sharing ...
Apache SkyWalking Apache SkyWalking is an applica...
Copy code The code is as follows: <iframe id=&...
Table of contents text 1. Prepare the machine 2. ...
1. Check sql_mode select @@sql_mode The queried v...
In the previous article - The charm of one line o...
1. Download 1. Click the latest download from the...
This article example shares the specific code of ...
Detailed explanation of mysql exists and not exis...
This article has compiled some so-called specific...
This article uses an example to illustrate the pa...
Deployment environment: docker container, liunx s...