Vue CLI build succeeds but shows blank page - Nginx server - vue.js

I am having a problem with getting a Vue app to load via Nginx. Basically, the npm run build finishes without any errors but when I go to the root URL the page is blank.
I get the following error, related to chunk-vendors and app, in dev tools console:
Uncaught SyntaxError: Unexpected token '<'
When I click on the related files it shows the html on a single line with a red squiggle line underneath and when I scroll over there is nothing inside the <div id="app">.
The build folder path is /home/ubuntu/apps/client/vue-crm/dist and my Nginx configuration looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/ubuntu/apps/client/vue-crm/dist;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
root /home/ubuntu/apps/client/vue-crm/dist;
try_files $uri/ /index.html =404;
}
}
I have run sudo nginx -t which comes back OK. Disclaimer, I am a bit of a newb when it comes to deploying using Vue CLI build and Nginx configuration so I could be missing something obvious.
I am running out of ideas on where the problem is. It seems my app is building fine, I just can't get it to load. Any help is much appreciated.

Related

ECS Fargate with Dockerized container nginx not loading static files

I have a webapp made in React and when I run the dockerimage locally, it works fine. No issues. When I deploy it to ECS Fargate with nginx it gives me a lot of weird errors.
Specifically, it cannot find the static assets. Here is my nginx file:
server {
listen ${PORT:-80};
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $$uri /index.html;
}
I am unsure what to change here, or in my yml files to get it to access the static stuff on ECS.
The error I am getting is the following:
Failed to load resource: the server responded with a status of 503
Any help is appreciated, thank you

Avoid Nginx to add '/' before query parameters

I'm currently developing a Nuxt SPA that will be served with Nginx.
When I run de nuxt server localy, everything is working fine. But when runing the app on nginx, I have an issue when adding query parameters.
Actually nginx automatically rewrite all URL to add a trailing /. Thus, when add query parameter I am automatically redirected to: www.exemple.com/my-path/?my-query-param=1234.
But what I want is to access www.exemple.com/my-path?my-query-param=1234 without the /?.
I tried adding rewrite ^/(.*)/$ /$1; to my nginx conf, unfortunately, this make me fall in a redirection loop (? -> /? -> ? -> /? -> ...).
my current nginx conf is very basic:
server {
listen 80;
index index.html;
include /etc/nginx/mime.types;
}
Can someone help me to fix my issue ?
Thanks in advance.
UPDATE:
I also tried try_files $uri $uri/index.html =404; without any success :-(

nginx - directory index of ... is forbidden, even for chmod 777

I'm trying to run rails app using nginx and unicorn based on Ryan Bates railcast (it's brand new rails new testapp).
So first step I want to test nginx only, no unicorn - just to work on index.html in public/. I point it to my testapp direcory, and get "index of "/var/www/testapp" is forbidden" error (I even set it all for 777 and got the same error)
My username: deployer, nginx: worker process user is www-data.
In my sites-enabled for my testapp I have symlink to /var/www/testapp/config/nginx.conf
:
server {
listen 80;
server_name beta.sitename.pl;
root /var/www/testapp;
}
Owner of www/ and all it's files and subdirectories is deployer and group www-data, all is set to 775.
Any idea where is the problem?
Try setting directory index properly, for example:
index index.html default.html index.php;
in your location block or use autoindex on option.
More info here

Passenger+Nginx show custom 500 page

I'm using Rails 3.2 with passenger+nginx. I want to display nice custom 500 page when the db server is down. I want to show something when my rails app cannot be started. Here is my nginx:
server {
listen 80;
server_name localhost;
root /var/www/store/public;
error_page 500 /500.html;
# root
location / {
passenger_enabled on;
rails_env production;
passenger_use_global_queue on;
}
}
The above configuration doesn't work at all. When it happens, it shows only:
Internal Server Error (500)
Any idea?
Phusion Passenger author here. Use passenger_intercept_errors off.
from the passenger documentation http://www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerFriendlyErrorPages
passenger_friendly_error_pages off
Which can be placed inside the http block, server block or location block, will not show the passenger error for startup failures and I believe link to the nginx supplied 500 error page.
mariow's link led me to the answer. The error files are in the templates folder. I use rvm, so my templates folder is at /home/forest.handford/.rvm/gems/ruby-2.0.0-p481/gems/passenger-4.0.50/resources/templates/ . Use find / -name templates | grep passenger to find yours. I'm changing undisclosed_error.html.template for my site, as it is the error that occurs when people type an invalid URL .

Nginx multiple locations with rails static assets

I am new to setting up my own server with nginx so forgive any ignorance. I may have just been using the wrong search terms to find the answers to my questions.
Anyway, I am using Rails 3, Nginx, and Unicorn at the moment on a VPS on rackspace. In my rails app I have about 500mb of files in public/ and I would like to use Nginx to serve these. Typically this is just:
server {
listen 80 default deferred;
# server_name example.com;
root /home/<my_user>/apps/<my_app>/current/public;
...
}
I can make this work if I add the 500mb in public to the git repo and then deploy with capistrano, but I don't want all of those files in my git repo. It makes no sense to store them there, but if I remove them then I have to manually go upload them to my public folder on the server every time I deploy.
Is there a way to make Nginx point to a second folder of assets for it to server? I tried the following:
location /static {
gzip on;
alias /home/deployer/static/;
}
I haven't had any luck getting this to work (trying to access the files via url.com/static/...) Anyone know what I am doing wrong?
Side note: all of the shown code is in my config/nginx.conf file and it SHOULD be overriding the settings via this line in my deploy.rb:
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
location /static/ {
root /home/deployer;
}
http://nginx.org/r/alias
http://nginx.org/r/root