Not loading css files on Nginx Server

Viewed 285

I used to code php on an Xampp server but recently changed to nginx. Everything is quiet different. Nevertheless, I got the main parts running. I can view the index.php page and I am able to visit other routes on localhost. ("http://localhost/index.php/register") The strange thing is that only on the index.php page, the css files can load but not on any other page.

Here is my 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;
#    }
#}

}

And the error that I get is this:

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"

And here is the error message from 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”.

I basically just coppied and pasted most of the items in nginx.conf from tutorials to get the routes running. If you have any idea on how to fix the css loading issue then please let me know.

Thanks in advance.

0 Answers
Related