2017-06-22 108 views
2

所以我有一个让Nginx为我的Laravel应用程序提供静态文件的问题。我可以在chrome的开发工具中看到请求正在到达这些文件所在的路径(http://mywebsite.com/public/css/style.css)。但他们根本没有被加载。我试图用很多方式让它工作,但它似乎并没有完成这项工作。任何人都可以帮助我吗?干杯!Laravel和Nginx的静态文件

server { 

    listen 80; 

    server_name mydomainname.com; 

    keepalive_timeout 70; 
    root /var/www/html/portfolio/public; 
    index index.php index.html index.htm index.nginx-debian.html; 
    autoindex on; 

    charset utf-8; 

    location/{ 
     root /var/www/html/portfolio/public; 
     index index.php index.html index.htm; 
     try_files $uri $uri/ /index.php$is_args$args; 
    } 

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

    access_log off; 
    error_log /var/log/nginx/myapp-error.log error; 

    sendfile on; 

    client_max_body_size 100m; 

    rewrite^/index.php last; 

    location ~ \.php$ { 
     try_files $uri =404; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors off; 
     fastcgi_buffer_size 16k; 
     fastcgi_buffers 4 16k; 
    } 

    location ~ /\.ht { 
     deny all; 
    } 
} 

基本上,/ public目录中有很多文件没有加载,但应该是。比如css,js,角度模板等的html文件...

+1

第一个红旗是“公开”,它不应该在那里(例如:'example.com/css/whatever.css')。 – Kyslik

+0

你需要打开你的日志(nginx的)并阅读它。 500是最可能的权限问题,但读取日志,可能编辑问题并添加日志的尾部。如果它的404也查看laravels日志。另外,你是否通过......'public/index.php'访问你的页面? – Kyslik

回答

0

这些网址不需要在路径中包含/public部分。 /public是您的网络资产的根源。所以你的网址应该是:

http://mywebsite.com/css/style.css 
+0

是的,但是当我在这样的路径上卷曲时,我得到了404,这就是为什么我认为它没有被服务 –

+0

@AndrewPomorski你在'public'文件夹中有文件夹'css'吗?你在那个文件夹里面有style.css吗? – Kyslik

+0

@Kyslik完全是。 –