【问题标题】:Nginx + Yii app = js,css - net::ERR_CONNECTION_REFUSEDNginx + Yii app = js,css - net::ERR_CONNECTION_REFUSED
【发布时间】:2018-06-02 19:37:34
【问题描述】:

我遇到了求救的情况。 我在新服务器上从 apache 迁移到 nginx,设置了 nginx+php-fpm+mariadb。

现在,除了 MVC 结构的错误之外,还有另一个错误 - Chrome 控制台充满红色 - net::ERR_CONNECTION_REFUSED 连接到 jpg 和 css 文件。

会是什么?是资产 Yii 组件中的错误还是 NGINX 配置中的错误? 这是我的配置。

server {
    listen 80; 
    server_name    example.ru; 
    root  /var/www/sites/example.ru; 

    set $yii_bootstrap "index.php";

    charset utf-8;

    location / {
        index  index.html $yii_bootstrap;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
        try_files $uri $uri/ /$yii_bootstrap?$args;
    }

    location ~ ^/(protected|framework|themes/\w+/views) {
       deny  all;
    }

    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
       try_files $uri =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass php-fpm;
                fastcgi_split_path_info  ^(.+\.php)(.*)$;
                set $fsn /$yii_bootstrap;
                if (-f $document_root$fastcgi_script_name){
                    set $fsn $fastcgi_script_name;
                }

                include fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;


                fastcgi_param  PATH_INFO        $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }

    location ~ \.css {
        add_header  Content-Type    text/css;
    }

    location ~ \.js {
        add_header  Content-Type    application/x-javascript;
    }

}

.htaccess 几乎是空白的

AddDefaultCharset UTF-8

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

【问题讨论】:

  • 再次检查获得 ERR_CONNECTION_REFUSED 的整个 url,并仔细检查服务器和端口是否正确。对我来说唯一有意义的是你连接到了错误的地方。

标签: php css .htaccess nginx yii


【解决方案1】:

我在迁移到新的 NGINX 服务器后忘记在我的 NGINX 服务器上启用 SSL,并且服务器正在搜索的所有脚本都以“https://”开头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多