NginX /location/ works but without img, css and js
See original GitHub issueI’m trying to selfhost grocy under the subdirectory /grocy/, I can move between /grocy/stockoverview and /grocy/calendar etc., but it won’t load any css, image or script.
I’ve installed it from the AUR, here is my configuration:
/etc/webapps/grocy/config.php
Setting('MODE', 'demo');
Setting('BASE_PATH', '/grocy');
Setting('BASE_URL', '/grocy');
/etc/nginx/nginx.conf
[...]
http {
server {
listen 443 ssl http2 default_server;
[...]
location /grocy/ {
proxy_pass http://127.0.0.1:5555;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_request_buffering off;
}
[...]
}
server {
listen 127.0.0.1:5555;
root /usr/share/webapps/grocy/public/;
index index.php;
location / {
try_files $uri /index.php$is_args$query_string;
add_header X-Content-Type-Options "" always;
}
location ~* \.(php|inc)$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
}
}
/etc/systemd/system/php-fpm.service
[...]
ReadWritePaths=/usr/share/webapps/grocy/data/
[...]
URLs are generated like this:
<link rel="icon" type="image/png" sizes="16x16" href="/grocy/img/appicons/favicon-16x16.png?v=2.6.1">
<link rel="manifest" href="/grocy/img/appicons/site.webmanifest?v=2.6.1">
[..]
<li class="nav-item nav-item-sidebar" data-toggle="tooltip" data-placement="right" title="Stock overview" data-nav-for-page="stockoverview">
<a class="nav-link discrete-link" href="/grocy/stockoverview">
<i class="fas fa-box"></i><span class="nav-link-text">Stock overview</span>
</a>
</li>
If I try to open /grocy/img/appicons/favicon-16x16.png?v=2.6.1 I get:
Type: Slim\Exception\HttpNotFoundException
Code: 404
Message: Not found.
File: /usr/share/webapps/grocy/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php
Line: 93
If I try to change ‘BASE_URL’ to “/grocy/public/”, where the static assets seems to be located, I get the above error anyway, and I also get that error with the previously working URLs like /grocy/calendar.
This is what I see under /grocy/calendar
EDIT I get the same results with
nginx.conf
[...]
location /grocy/ {
proxy_pass http://127.0.0.1:5555/grocy/;
[...]
location /grocy/ {
try_files $uri /index.php$is_args$query_string;
[...]
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
nginx not serving css/js images - Stack Overflow
You have one location that sends all requests to PHP. You are not serving static files (such as js/css) with Nginx.
Read more >Pitfalls and Common Mistakes | NGINX
This works. Putting root inside of a location block will work and it's perfectly valid. What's wrong is when you start adding location...
Read more >Nginx ingress - all of css js and images 404 · Issue #333
I can access it via http, but only the html is accessible, all of its css js and images 404. ingress apiVersion: extensions/v1beta1...
Read more >Nginx location directive examples - DigitalOcean
The location directive within NGINX server block allows to route request to correct location within the file system. The directive is used ...
Read more >How to configure nginx to find subfolders for /js /css related to ...
I'm not sure why your index.html did work though not having tried it myself. One reason could be that because your location coincidentally ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the feedback.
I’ve already tried it, but unfortunately that’s not the issue.
I finally found a way to make it work: remove the
BASE_PATH
and add a trailing slash in theproxy_pass
directive. These are the changes I made to my original configuration in the first post, if someone else can test this subdirectory configuration I think it may be an useful addition to the community installation guides./etc/webapps/grocy/config.php
/etc/nginx/nginx.conf