首页 > 解决方案 > 不在 Nginx 服务器上加载 css 文件

问题描述

我曾经在 Xampp 服务器上编写 php,但最近更改为 nginx。一切都安静不同。尽管如此,我还是让主要部分运行起来。我可以查看 index.php 页面,并且可以访问 localhost 上的其他路由。("http://localhost/index.php/register") 奇怪的是只有index.php页面可以加载css文件,其他页面不能加载。

这是我的 nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
include       mime.types;
default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;


    location / {
        try_files $uri $uri/ /index.php?$args;
        root   html;
        index  index.php index.html index.htm;
    }

    #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;
    }

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

    #location @missing {
    #    rewrite ^ $scheme://$host/index.php permanent;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root html;
        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;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

我得到的错误是:

2020/11/15 19:03:09 [error] 800#5224: *24 CreateFile() 

"C:\Users\Admin\Desktop\nginx-1.19.4/html/index.php/css/bootstrap.min.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /index.php/css/bootstrap.min.css HTTP/1.1", host: "localhost", referrer: "http://localhost/index.php/register"
2020/11/15 19:03:09 [error] 800#5224: *26 CreateFile() "C:\Users\Admin\Desktop\nginx-1.19.4/html/index.php/css/styles.css" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /index.php/css/styles.css HTTP/1.1", host: "localhost", referrer: "http://localhost/index.php/register"

这是来自 Mozilla Firefox 的错误消息:

The stylesheet http://localhost/index.php/css/bootstrap.min.css was not loaded because its MIME type, “text/html”, is not “text/css”.

我基本上只是从教程中复制并粘贴了 nginx.conf 中的大部分项目,以使路由运行。如果您对如何解决 css 加载问题有任何想法,请告诉我。

提前致谢。

标签: phpcssnginxconfiguration

解决方案


推荐阅读