gpt4 book ai didi

php - Nginx - Rails 上的 Wordpress 博客加载带有 mime 类型文本/html 的样式和脚本

转载 作者:可可西里 更新时间:2023-10-31 22:45:36 24 4
gpt4 key购买 nike

我刚刚在 Rails 应用程序的/blog 目录下安装了一个 Wordpress 博客,在 Unicorn 和 Nginx 上运行,当我转到我的 domain.com/blog 页面时,我的样式表和脚本没有在浏览器中正确加载. Chrome 控制台给我以下错误:

  • 资源解释为样式表但以 MIME 类型文本/html 传输
  • 资源解释为脚本但以 MIME 类型文本/html 传输

一直在尝试解决这个问题,并在 SO 上尝试了很多解决方案,但仍然无法通过...似乎需要在我的 Nginx 配置上进行一些更改,特别是对于 blog/php 位置.这是我的配置:

upstream unicorn {
server unix:/tmp/unicorn.domain.sock fail_timeout=0;
}

server {
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}

server {
listen 80 default deferred;
server_name domain.com;
root /home/dcs/htdocs/domain/current/public;

access_log /home/dcs/htdocs/domain/log/access.log;
error_log /home/dcs/htdocs/domain/log/error.log;


location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME home/dcs/htdocs/domain/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}


location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}

try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}

error_page 500 502 503 504 /500.html;
keepalive_timeout 10;
}

最佳答案

经过大量搜索,我终于找到了 this solution .

问题似乎是我需要在“location/blog”中为应用程序添加一个根,并将“location ~ .php$”嵌套在/blog 中。这是我的 Nginx 配置,现在可以在使用 Unicorn 的 Rails 应用程序中用于 Wordpress 博客,以防其他人需要它:

upstream unicorn {
server unix:/tmp/unicorn.domain.sock fail_timeout=0;
}

server {
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}

server {
listen 80 default deferred;
server_name domain.com;
root /home/dcs/htdocs/domain/current/public;

access_log /home/dcs/htdocs/domain/log/access.log;
error_log /home/dcs/htdocs/domain/log/error.log;

location /blog {
root /home/dcs/htdocs/domain;
index index.php;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME home/dcs/htdocs/domain/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}

try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}

error_page 500 502 503 504 /500.html;
keepalive_timeout 10;
}

关于php - Nginx - Rails 上的 Wordpress 博客加载带有 mime 类型文本/html 的样式和脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30012535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com