我的css和javascript文件没有运行

时间:2017-06-03 17:12:33

标签: laravel nginx laravel-5.4

我为我的laravel项目安装了Nginx服务器。但是css和javascript文件无效。 Css和javascript文件可在服务器上下载。例如http://myipaddress/css/bootstrap.css下载bootstrap.css文件。我像这样调用像<link href="{{ URL::asset('css/bootstrap.css') }}" rel="stylesheet">这样的css文件。 enter image description here

我的源代码enter image description here

我的公用文件夹权限enter image description here

/etc/nginx/sites-available/default如下所示

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

你能帮我解决这个问题吗?

谢谢。

2 个答案:

答案 0 :(得分:1)

你看过电影Hidden Figures了吗?这是一个场景,主角可以通过将编辑后的纸张放到灯上来查看删失的信息。您可能会问的相关性?你在问题上的审查并不是很难规避。

当我访问您的服务器并检查控制台时,我得到了......

  

未加载样式表http://###/css/bootstrap.css,因为其MIME类型&#34; application / octet-stream&#34;不是&#34; text / css&#34;。
  未加载样式表http://###/css/font-awesome.min.css,因为其MIME类型&#34; application / octet-stream&#34;不是&#34; text / css&#34;。

  未加载样式表http://###/css/style.css,因为其MIME类型&#34; application / octet-stream&#34;不是&#34; text / css&#34;。

修复样式表的mime-types,它们应该正确加载。我会开始查看df = read.csv("myfile.csv") 并确认您已将css扩展名映射到/etc/nginx/mime.types

答案 1 :(得分:0)

我不知道宅基地,我会发布这个作为评论,但我没有足够的代表,但也许改变用户所有权到www数据会起作用吗?

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

然后,如果它有效,您可能必须更改存储文件夹的所有权,如果您允许文件上传。