0

I installed Nginx server for my laravel project. But css and javascript file not working. Css and javascript file downloadable on server. For example http://myipaddress/css/bootstrap.css download the bootstrap.css file. I call the css file like <link href="{{ URL::asset('css/bootstrap.css') }}" rel="stylesheet"> like this. enter image description here

My source code enter image description here

My public folder permissionsenter image description here

/etc/nginx/sites-available/default looks like the following

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

# SSL configuration
#
 listen 443 ssl default_server;
 listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/english4-u.com/public;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm;

server_name english4-u.com;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.php?$query_string;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#   include snippets/fastcgi-php.conf;
#
#   # With php7.0-cgi alone:
#   fastcgi_pass 127.0.0.1:9000;
#   # With php7.0-fpm:
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    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;
}

access_log /var/log/nginx/english4-u.com-access.log;
error_log  /var/log/nginx/english4-u.com-error.log error;

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt  { access_log off; log_not_found off; }

charset utf-8;

error_page 404 /index.php;}

Can you help me with this?

Thank You.

6
  • No one can help you unless we know how the CSS or JavaScript is being used. For all we know you're not actually making use of any bootstrap CSS rules in your HTML. Commented Jun 3, 2017 at 17:30
  • @apokryfos thank you for your feedback. My css file call <link href="{{ URL::asset('css/bootstrap.css') }}" rel="stylesheet"> and runnig my local storage. Homestead installed on my local. Commented Jun 3, 2017 at 17:41
  • Long shot-in Chrome go in your tools,network tab and check disable cache.Then do a ctrl+F5 for refresh.Also show your css scripts where you load them. Commented Jun 3, 2017 at 17:56
  • I am using bootstrap classes. The project running my local but not working on the server. @lewis4u Commented Jun 3, 2017 at 18:09
  • I have deleted my answer because it didn't help you...if you want i can connect to your pc with team viewer to fix it...i think it has to be something with file permission Commented Jun 3, 2017 at 18:35

2 Answers 2

1

Have you seen the movie Hidden Figures? There's a scene where a main character can see censored information by holding up redacted papers to a lamp. The relevance you may ask? Your censoring in the question wasn't very hard circumvent.

When I visit your server and check the Console I get ...

The stylesheet http://###/css/bootstrap.css was not loaded because its MIME type, "application/octet-stream", is not "text/css".

The stylesheet http://###/css/font-awesome.min.css was not loaded because its MIME type, "application/octet-stream", is not "text/css".

The stylesheet http://###/css/style.css was not loaded because its MIME type, "application/octet-stream", is not "text/css".

Fix the mime-types of the stylesheets and they should load properly. I would start looking in /etc/nginx/mime.types and verify that you've mapped the css extension to text/css.

Sign up to request clarification or add additional context in comments.

1 Comment

I did not watch the movie, but I will watch. Thank you.
0

I dont know homestead and I would have posted this as comment but I don't have enough rep for that but maybe changing also the user ownership to www-data would work?

sudo chown www-data:www-data -R projectfolder

Then if it works you may have to change ownership for the storage folder if you are allowing file uploads.

3 Comments

Thank you for your feedback. I used the command. But nothing changed.
Maybe posting your ngix conf would help? If the assets url are correct and if you visit them you download them maybe it's just a setting on the webserver or php.ini.
I do not think it's related to PHP. But I attached Nginx config. Maybe related to Nginx. @thepassenger

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.