wordpress 访问页面样式丢失
一、使用环境
CentOS 6.8 x64
php 5.5
nginx 1.10.2
wordpress 4.8.2
二、问题描述
今天在更改了 nginx.conf 文件之后出现了访问 wordpress 页面样式丢失的情况,抓包显示访问静态文件 .css,.js 文件返回的状态码是 403。
三、问题分析
原因是,在 nginx.conf 中多加了如下这段配置:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
四、解决方法
访问服务器上的 nginx.conf 文件,编辑该文件,删除 nginx.conf 中多余的部分。重启 nginx
$NGINX_HOME/sbin/nginx -s reload
注:
1. `NGINX_HOME` 就是 /usr/local/nginx。
2. nginx.conf 的位置与安装位置有关,比如我的 nginx 使用编译安装在 `/usr/local/nginx` 目录下,那么我的 nginx.conf 则在 `/usr/local/nginx/conf/nginx.conf`。
3. 如果网站的 nginx 代理配置是被拆分到其他位置的文件中然后使用 `include FILE_NAME.conf` 的方法导入到 nginx.conf 中的,那么需要修改的就是对应的配置文件。
### 附录一:nginx.conf 配置示 ###
---
我的 wordpress 的配置示例如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
root /data/www/wordpress;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.jiangzhuolin.com;
charset utf-8;
index index.php index.html index.htm;
# wordpress 固定链接生效-开始
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# wordpress 固定链接生效-结束
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
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 html;
}
access_log logs/jiangzhuolin.com_access.log;
}
}
附录二、wordpress 官方 nginx 配置
wordpress 官方给出的 nginx 的推荐配置如下
https://codex.wordpress.org/Nginx
附件列表
近期评论