技术解析

LNMP 跑了个 wordpress,页面 CSS 和图片展示不起来,后台 GET 图片出来个问号
0
2021-05-20 19:42:08
idczone

不知道标题描述清楚没有 wordpress 页面现在丑的雅痞,CSS 和图片感觉加载不起来,就在浏览器里面去专门访问图片,拿到个一个问号。 后台用 curl 去 GET,跟浏览器情况一致。 是图片太大,buffer 太小,感觉跟 NGINX 配置有关系,萌新求指导?

[[email protected] images]# pwd

/opt/nginx/html/blog/wp-content/themes/twentyseventeen/assets/images [[email大带宽服务器60;protected] images]# l total 536 -rwxrwxrwx 1 nginx nginx 117713 Nov 23 2016 coffee.jpg -rwxrwxrwx 1 nginx nginx 93540 Nov 23 2016 espresso.jpg -rwxrwxrwx 1 nginx nginx 114854 Nov 17 2016 header.jpg -rwxrwxrwx 1 nginx nginx 171858 Nov 23 2016 sandwich.jpg -rwxrwxrwx 1 nginx nginx 42656 Sep 25 09:49 svg-icons.svg

[[email protected] ~]# curl -i -X GET http://104.225.150.251/wp-content/themes/twentyseventeen/assets/images/header.jpg

HTTP/1.1 200 OK Server: nginx/1.12.2 Date: Sun, 28 Jan 2018 17:24:52 GMT Content-Type: text/html Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/5.3.27

?[[email protected] ~]# l

NGINX 配置

worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; error_page 500 502 503 504 /50x.html; fastcgi_buffers 512 128k; location = /50x.html { root html; } location / { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } }


折腾什么,直接宝塔

不知道标题描述清楚没有
wordpress 页面现在丑的雅痞,CSS 和图片感觉加载不起来,就在浏览器里面去专门访问图片,拿到个一个问号。
后台用 curl 去 GET,跟浏览器情况一致。
是图片太大,buffer 太小,感觉跟 NGINX 配置有关系,萌新求指导?
[[email&images]pwd
/opt/nginx/html/blog/wp-content/themes/twentyseventeen/assets/images
[[email&images]l
total 536
-rwxrwxrwx 1 nginx nginx 117713 Nov 23 2016 coffee.jpg
-rwxrwxrwx 1 nginx nginx 93540 Nov 23 2016 espresso.jpg
-rwxrwxrwx 1 nginx nginx 114854 Nov 17 2016 header.jpg
-rwxrwxrwx 1 nginx nginx 171858 Nov 23 2016 sandwich.jpg
-rwxrwxrwx 1 nginx nginx 42656 Sep 25 09:49 svg-icons.svg

[[email&~]curl -i -X GET http://104.225.150.251/wp-content/themes/twentyseventeen/assets/images/header.jpg
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sun, 28 Jan 2018 17:24:52 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.3.27
?[[email&~]l

NGINX 配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
error_page 500 502 503 504 /50x.html;
fastcgi_buffers 512 128k;
location = /50x.html {
root html;
}
location / {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}


只是感觉很奇怪,想瞅瞅

把图片等静态资源扔给 PHP 处理
fastcgi 不是这么用的

去 /var/log 看日志咯……

新手还是推荐宝塔之类的面板的,但是不要依赖宝塔,要去学它怎么写配置。

别听他们的什么宝塔,直接 oneinstack

不建议用面板吧!用起来感觉很怪,而且我一般都认为我自己都能写一个,还能做更好的管理优化,要这个东西来干嘛?日积月累的脚本,比这个强大多了,但是没有好看的包装,拿不出手!

歪了! 我之前也是无法访问部分图片,加上这段代码就可以了,这代码包含了防盗链的,就是第二行和下面的 IF 语句

lnmp.org ,包你满意。
你还可以学一下他的配置

你们在开发、测试、生产环境都用面板吗?

OneinStack 还可以

只是缺一行 nginx 代理 jpg css 这种静态资源的配置而已,
楼主去 wp 官网撸个 nginx 配置不就好了
https://codex.wordpress.org/Nginx#General_WordPress_rules

规则错了。

Nginx 配置错了,参考这两个:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-on-ubuntu-16-04

应该不是 LNMP 的锅,阿里云+LNMP 跑好几个 wordpress,都没有问题,除了开始的时候遇到不能更新

感谢各位,按照 13 楼的建议,撸了个配置,已经 ok 了,多谢 @zjsxwc
刚接触 Nginx,想都理解下

数据地带为您的网站提供全球顶级IDC资源