您的位置:首页 > 运维架构 > Nginx

wordpress 快速搭建个人博客 教程 (二) 配置 nginx

2018-03-16 18:22 856 查看
现在我们需要配置一下 nginx 服务器

首先使用 cp 命令把我们下载好的 wordpress 拷贝到 nginx 根目录

cp -rf wordpress /usr/share/nginx/html/




然后我们需要更改nginx的配置文件

使用 cd 命令跳转到 nginx 配置目录
cd /etc/nginx/conf.d/
并备份一份 default.conf 为 default.conf.bak



使用 vim 编辑器编辑 default.conf

把内容编辑为如下

server {
listen       80;
server_name  localhost;

#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;

location / {
root   /usr/share/nginx/html/wordpress;
index  index.html index.htm index.php;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1; #}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root           /usr/share/nginx/html/wordpress;
server {
listen       80;
server_name  localhost;

#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;

location / {
root   /usr/share/nginx/html/wordpress;
index  index.html index.htm index.php;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1; #}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root           /usr/share/nginx/html/wordpress;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}


然后 按 ESC 键 在按 wq 保存退出

然后我们就可以访问 wordpress 了 如下图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: