WordPress搭建教程

阅读 429
收藏 7
2018-03-07
原文链接:labradors.work

大学毕业一直用Hexo博客,刚开始在本地构建提交,然后通过Github Page解析。后来觉得烦,就用自己的服务器搭建博客,利用Github钩子提交数据到服务器,服务器负责构建和部署。但是还是要通过Git,每次想换博客似乎都必须要和git扯上关系。最近想把博客系统独立,随时随地可写,随时发布,本想用Ghost,发现Ghost是收费的,最后选择了WordPress。还没有玩熟悉,不过看起来还行。使用Docker搭建,方便流畅。

服务器

本博客使用Vultr 搭建,Vultr现在变渣了,不过耐不住便宜啊。用来放博客还是可以的。直接点连接进去注册部署就行了。

Docker安装

官方的安装教程还是蛮麻烦的,阿里有一键搭建教程:

curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
 

  • 自启动

sudo systemctl enable docker
sudo systemctl start docker
 

Docker脚本

  • 新建文件夹

mkdir wordpress
cd wordpress
 

  • 创建docker-compose.yml

vim docker-compose.yml
 

  • 复制内容

version: '2'
services:
  wordpress:
    image: wordpress:latest # https://hub.docker.com/_/wordpress/
    ports:
      - 8081:80 # change ip if required
    volumes:
      - ./config/php.conf.uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./wp-app:/var/www/html # Full wordpress project
      #- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development
      #- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: password
    depends_on:
      - db
    networks:
      - wordpress-network
  db:
    image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
    ports:
      - 3306:3306 # change ip if required
    volumes:
      - ./wp-data:/docker-entrypoint-initdb.d
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_ROOT_PASSWORD: password
    networks:
      - wordpress-network
networks:
  wordpress-network:
      driver: bridge
 

  • 启动

docker-compose up -d
 

安装配置Nginx

  • 安装

apt-get install nginx
 

  • 配置

server {
    #listen 80 default_server;
    #listen [::]:80 default_server;
 
    # SSL configuration
    #
    listen 443 ssl default;
    listen [::]:443 ssl default;
    server_name labradors.work  mis.labradors.work;
    ssl  on;  
        ssl_certificate /etc/chain/labradors.work.pem;
        ssl_certificate_key /etc/chain/labradors.work.key;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.co
 
    # Add index.php to the list if you are using PHP
    # 证书请自己去cloudflare申请,15年还是可以的。
 
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        proxy_connect_timeout 500s;
        proxy_read_timeout 500s;
        proxy_send_timeout 500s;
        proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #proxy_pass http://172.17.0.1:8081;
        proxy_pass http://localhost:8081;
    }
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php7.0-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # With php7.0-fpm:
    #   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    #}
 
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}
 
 
server {
    listen 80 default;
    server_name labradors.work  mis.labradors.work;
    return 301 https://$host$request_uri;
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#  listen 80;
#  listen [::]:80;
#
#  server_name example.com;
#
#  root /var/www/example.com;
#  index index.html;
#
#  location / {
#      try_files $uri $uri/ =404;
#  }
#}
 

评论