Issue
I've been preparing for production with my rails application and I'm having a lot of trouble with nginx. Compared to development where the assets weren't precompiled, nothing works now. I use sprockets to handle the css, images and fonts and webpacker for the javascript. Problem is, whenever I try anything in the tutorials I see, it doesn't work. I always get erors such as "No route matches [GET] "/packs/js/" or "No route matches [GET] "/assets/...".
Here's what my default.conf looks like :
upstream railsapp {
server hubsite:3000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /app/public;
# Deny requests for files that should never be accessed
location ~ /\. {
deny all;
}
location ~* ^.+\.(rb|log|go|exe)$ {
deny all;
}
try_files $uri @rails;
# serve static (compiled) assets directly if they exist (for rails production)
location ~ ^/(assets|packs|images|javascripts|stylesheets|swfs|system)/ {
try_files $uri @rails;
access_log off;
gzip_static on;
# to serve pre-gzipped version
expires max;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
location @rails {
proxy_pass http://railsapp;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
}
# 404 HANDLING
location = /404.html {
internal;
}
}
I also tried to modify the proxy_pass for my proper url, but it didn't work. Basically, there would always be a "/portal/" after the url, so like "mytestwebsite.com/portal/signin". All of this is running in a docker container and the root path does seem to be correct from what I checked.
If anyone has an idea as to why it doesn't work, feel free to point me in the good direction! Thanks!
Solution
Everything was fine with nginx, problem was that I wasn't properly linking my volumes with my docker-compose!
Answered By - Jeune Padawan Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.