javascript - Laravel 5.4 Served in subdirectory Nginx. 404 when including js files -
my problem serving css , js files using laravel 5.4 on nginx server (ubuntu). have configured server serve application nested sub-directory (not in root of web server). routing working. see:
- https://zwestwind.com/sandboxes/zypth/blog/tasks
- https://zwestwind.com/sandboxes/zypth/blog/posts
- and ..blog/ well.
the problem cannot include js files (and css). js file in "blog/public/js/posts.js".
attached below site configuration, , code include js file in blade template. can view error in console when hit site.
server configuration:
server { return 404; } server { listen 80; listen [::]:80 ipv6only=on; listen 443 ssl; root /var/www/zwestwind.com/html; index index.php index.html index.htm; # make site accessible http://localhost/ #server_name example.com www.example.com; server_name zwestwind.com www.zwestwind.com; ssl on; ssl_certificate /etc/nginx/ssl/pub_clf_origin.pem; ssl_certificate_key /etc/nginx/ssl/priv_clf_origin.key; ssl_protocols tlsv1 tlsv1.1 tlsv1.2; ssl_ciphers eecdh+chacha20:eecdh+aes128:rsa+aes128:eecdh+aes256:rsa+aes256:eecdh+3des:rsa+3des:!md5; ssl_prefer_server_ciphers on; location / { # first attempt serve request file, # directory, fall displaying 404. try_files $uri $uri/ =404; # uncomment enable naxsi on location # include /etc/nginx/naxsi.rules } # route laravel project: $uri = /sandboxes/zypth/blog/public/index.php location ~ ^/sandboxes/zypth/blog { alias /var/www/zwestwind.com/html/sandboxes/zypth/blog/public; try_files $uri $uri/ @laravel; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #fastcgi_index index.php; include fastcgi_params; fastcgi_param script_filename /var/www/zwestwind.com/html/sandboxes/zypth/blog/public/index.php; } } location @laravel{ rewrite /sandboxes/zypth/blog/(.*)$ /sandboxes/zypth/blog/index.php?/$1 last; } # nginx-naxsi used nginx-naxsi-ui : process denied requests #location /requestdenied { # proxy_pass http://127.0.0.1:8080; #} error_page 404 /404.html; # redirect server error pages static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass php scripts fastcgi server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # note: should have "cgi.fix_pathinfo = 0;" in php.ini # php5-cgi alone: fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access .htaccess files, if apache's document root # concurs nginx's 1 # #location ~ /\.ht { # deny all; #} }
blade code include js file:
<script src="{{ url::asset('posts.js', true) }}"></script>
things have tried:
- i have tried using 'js/posts.js' , many other variations, including hardcoded paths such 'zwestwind.com/sandboxes/zypth/blog/public/posts.js' no avail (with protocol, can post 2 links due reputation).
- adding location block: location ~ .js$ {...} add content-header of application/x-javascript
- i have configured vhost server serve same application @ (http)blog.zwestind.com/posts. routing , inclusion of css/js files works there, check out. server config sub domain specified in laravel installation guide.
i guessing issue stems server config problem primary domain... ie) location block listening "^/sandboxes/zypth/blog" catching request js file , modifying uri, resulting in 404. how fix this?
when script works, "posts.js ready!" in console (see sub domain on http example).
thanks.
p.s. if curious why want serve app (and more) in nested directory, because want host live demo apps using 1 ssl cert via 1 domain while learning how configure web servers. server not intended heavy traffic.
Comments
Post a Comment