这个站点是如何搭建的

这篇文章将介绍博主在 Debian Jessie 上搭建 WordPress 博客的过程。

安装 HTTP 服务器

我使用的是 nginx 作为本站点的 HTTP 服务器

<br />
# aptitude install nginx<br />

安装 PHP

<br />
# aptitude install php5 php5-fpm php5-mysql php5-cgi<br />

安装数据库

数据库使用 mariadb

<br />
# aptitude install mariadb-server mariadb-client<br />

创建数据库

<br />
# mysql -u root -p<br />

<br />
mysql &gt; CREATE DATABASE wordpress;<br />
mysql &gt; GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY &#039;password&#039;;<br />
mysql &gt; FLUSH PRIVILEGES;<br />
mysql &gt; exit<br />

下载并解压 WordPress 安装包

<br />
# wget https://wordpress.org/latest.tar.gz<br />
# tar -xf latest.tar.gz /var/www/wordpress<br />

配置 HTTP 服务器

站点配置文件
/etc/nginx/sites-available/zhrichard.me

<br />
server {<br />
    server_name zhrichard.me;<br />
    root /var/www/zhrichard.me;</p>
<p>    index index.php;</p>
<p>    include global/restrictions.conf;</p>
<p>    # Additional rules go here.</p>
<p>    # Only include one of the files below.<br />
    include global/wordpress.conf;<br />
#  include global/wordpress-ms-subdir.conf;<br />
#  include global/wordpress-ms-subdomain.conf;<br />
}<br />


全局限制
/etc/nginx/global/restrictions.conf

<br />
# Global restrictions configuration file.<br />
# Designed to be included in any server {} block.<br />
location = /favicon.ico {<br />
    log_not_found off;<br />
    access_log off;<br />
}</p>
<p>location = /robots.txt {<br />
    allow all;<br />
    log_not_found off;<br />
    access_log off;<br />
}</p>
<p># Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).<br />
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)<br />
location ~ /\. {<br />
    deny all;<br />
}</p>
<p># Deny access to any files with a .php extension in the uploads directory<br />
# Works in sub-directory installs and also in multisite network<br />
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)<br />
location ~* /(?:uploads|files)/.*\.php$ {<br />
    deny all;<br />
}<br />


WordPress 规则
/etc/nginx/global/wordpress.conf

<br />
# WordPress single site rules.<br />
# Designed to be included in any server {} block.</p>
<p># This order might seem weird - this is attempted to match last if rules below fail.<br />
# http://wiki.nginx.org/HttpCoreModule<br />
location / {<br />
    try_files $uri $uri/ /index.php?$args;<br />
}</p>
<p># Add trailing slash to */wp-admin requests.<br />
rewrite /wp-admin$ $scheme://$host$uri/ permanent;</p>
<p># Directives to send expires headers and turn off 404 error logging.<br />
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {<br />
       access_log off; log_not_found off; expires max;<br />
}</p>
<p># Uncomment one of the lines below for the appropriate caching plugin (if used).<br />
#include global/wordpress-wp-super-cache.conf;<br />
#include global/wordpress-w3-total-cache.conf;</p>
<p># Pass all .php files onto a php-fpm/php-fcgi server.<br />
location ~ [^/]\.php(/|$) {<br />
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;<br />
    if (!-f $document_root$fastcgi_script_name) {<br />
        return 404;<br />
    }<br />
    # This is a robust solution for path info security issue and works with &quot;cgi.fix_pathinfo = 1&quot; in /etc/php.ini (default)</p>
<p>    include fastcgi_params;<br />
    fastcgi_index index.php;<br />
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br />
#  fastcgi_intercept_errors on;<br />
    fastcgi_pass php;<br />
}<br />

修改 wp-config.php

在 wp-config.php 加入数据库相关的配置

<br />
. . .<br />
// ** MySQL settings - You can get this info from your web host ** //<br />
/** The name of the database for WordPress */<br />
define(&#039;DB_NAME&#039;, &#039;wordpress&#039;);</p>
<p>/** MySQL database username */<br />
define(&#039;DB_USER&#039;, &#039;wordpressuser&#039;);</p>
<p>/** MySQL database password */<br />
define(&#039;DB_PASSWORD&#039;, &#039;password&#039;);<br />
. . .<br />

启动 HTTP 服务器并配置 WordPress

启动 nginx

<br />
# systemctl start nginx<br />

访问 站点 即可配置 WordPress。

Troubleshooting

打开站点发现是空白页面

/etc/nginx/fastcgi_params 文件最后加入一行

<br />
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;<br />

参考

发表评论

电子邮件地址不会被公开。 必填项已用*标注