How can I deploy an Ember app on Digital Ocean? - nginx

I have an Ember app running on port 4200 that uses an Express API on port 4500. I have uploaded my API to:
/var/www/my-api-domain.com/public_html/
I have also edited the nginx sites-available file:
location /
{
proxy_pass http://localhost:4500;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
I SSH into the server, change directory to my API, and run node server and this works! When I visit my IP in the browser, I see my API working properly:
http://159.203.31.72
I then ran ember build -prod locally and uploaded the contents of the resulting dist folder to:
/var/www/my-ember-domain.com/public_html/
I once again updated the nginx sites-available with:
location /ember
{
proxy_pass http://localhost:4200;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Now what? Typically, when I run the site locally, I'd run ember server, but the resulting files in dist look much different and I don't have ember cli installed on the server. As I read about it, that doesn't seem to be the proper approach.
When I hit http://159.203.31.72/ember in the browser, I get an nginx 502 Bad Gateway. How can I serve my Ember app?

ember server starts a development server which should not be used in production. Build your app using ember build --prod. Afterwards you will find your assets in dist/ folder. Serve that ones with nginx and you are done. There is an example nginx.conf in ember-cli docs: https://ember-cli.com/user-guide/#deploying-an-https-server-using-nginx-on-a-unixlinuxmacosx-machine
You could use ember-cli-deploy if you have to set up a more complex deployment workflow.

Related

Nextjs site says 500 when creating build

I have a website (https://checkeden.com) built in Next.js version 12 which is deployed in AWS lightsail server. Whenever I made some changes and create a new build the page shows 500 internal server error and when the build is done then is start working. I think I am doing something wrong here. Can someone guide me to how to deploy Next.js application in Lightsail server without 500 error when build is in process?
Also I am using Nginx Reverse proxy to server my website
below is the code snippest for Nginx configuration
server {
server_name checkeden.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I tried some youtube videos and blogs but didn't get what I want.

Access a web app (ASP.NET) from another machine using nginx

Well, here we go.
I have an instance in Azure with ubuntu and I'm trying to access an web application out of this machine (Not LocalHost).
First I've installed all dotnet things to make a test application and runned
dotnet new mvc
I check inside Azure machine localhost:5000 and this app test work well.
Then I installed nginx to access my application remotelly. When I access the public IP I can see a page of nginx.
nginx Page
I've try to config thousand times to when I access the public IP the nginx redirect to my web app running in Azure Localhost.
One configuration I've try was
/etc/nginx/sites-enabled
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Any Idea to make this works?
Sry for bad english
You have missed server_name parameter.
And if that's the only one config in config dir, then also add default_server option to listen directive, like this:
server {
listen 80 default_server;
server_name my.domain.com;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Change my.domain.com to appropriate FQDN of your Azure instance, so that you can make requests not only by entering IP address in browser, but also with a host name.
And make sure that you have included that config in nginx.conf file, like:
include /etc/nginx/sites-enabled/*;
Hope it will help you to figure out.

Nginx: Proxy pass / proxy redirect to shiny web applications

We are trying to update our internal server infrastructure and to proxy all accesses to our R shiny webservers through an Nginx server. Im able to get a response from the shiny server but Im not able to get related files like css/js through the Nginx server.
Setup:
2 docker container (1 for hosting nginx, 1 running R for a shiny application)
both docker container are members of an docker network
shiny server listens to port 7676 (internal ip-adress 172.18.0.3)
nginx server is hosting few static html files with iFrames (legacy, cant get ride off), which should show content of the shiny server
accessing nginx-server/QueryLandscape.html loads the page with the iFrame <iframe src="ilandscape"></iframe>
iFrame works: it loads the static part of R-shiny application, but it doesnt load the related JS/CSS/....(e.g. http://nginx-server:8001/ilandscape/shared/shiny.css)
within the nginx-docker container i can access this css file wget 172.18.0.3:7676/shared/shiny.css
Nginx.conf
location /ilandscape/ {
proxy_pass http://172.18.0.3:7676/;
#proxy_redirect http://172.18.0.3:7676/ $scheme://$host/;
# websocket headers
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_read_timeout 20d;
proxy_set_header Host $host;
}
What am I missing in my nginx conf to proxy/redirect http://nginx-server:8001/ilandscape/shared/shiny.css --> 172.18.0.3:7676/shared/shiny.css ?
Thanks for your help,
Tobi
Looks like the iframes acting as a browser are receiving the hostname instead of the full path to the resources. Can you set up the following ReverseProxy headers and give it a go:
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Basically you have a proxy at the moment, and we want a reverse proxy too. Let me know if this works.

Nginx not displaing Phoenix web app

I'm trying to deploy a basic Phoenix app to a DigitalOcean server running ubuntu 14.04. I'm using exrm to generate the release. The release works when I test it on my local machine and on the server. I'm following the Phoenix guides on deployment. The thing that doesn't seem to work is the last part with the nginx server setup. For some reason I cant get it to load anyting but the default page. When I run the
nginx -t # command. It says everything is fine.
I've tried editing the /etc/nginx/sites-available files. Doesn't seem to do anything. I've tried restarting the nginx server with
sudo service nginx reload
sudo service nginx restart
But that doesn't seem to work either.
And this is the content of my /etc/nginx/sites-available/my_app.conf
upstream my_app {
server 127.0.0.1:4000;
}
server{
listen 80;
server_name www.example.com;
location / {
try_files $uri #proxy;
}
location #proxy {
include proxy_params;
proxy_redirect off;
proxy_pass http://my_app;
# The following two headers need to be set in order
# to keep the websocket connection open. Otherwise you'll see
# HTTP 400's being returned from websocket connections.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
Update: Tried connecting directly via server_ip:port, and it worked. The url still doesnt display anything.
Solved: For some reason deleting this solves the problem.:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Solved: For some reason deleting this solves the problem.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

Websockets on ElasticBeanstalk giving 404

I'm trying to deploy a websocket server to Elastic Beanstalk.
I have a Docker container that contains both nginx and a jar server, with nginx just doing forwarding. The nginx.conf is like this:
listen 80;
location /ws/ { # <-- this part only works locally
proxy_pass http://127.0.0.1:8090/; # jar handles websockets on port 8090
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / { # <-- this part works locally and on ElasticBeanstalk
proxy_pass http://127.0.0.1:8080/; # jar handles http requests on port 8080
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-Host $server_name;
}
I can run this docker locally and everything works fine - http requests are served, and I can connect websockets using ws://localhost:80/ws/ However, when I deploy to Elastic Beanstalk, http requests are still ok, but trying to connect websockets on ws://myjunk.elasticbeanstalk.com:80/ws/ gives a 404 error. Do I need something else to allow websockets on Elastic Beanstalk?
Ok, got it working. I needed the ElasticBeanstalk load balancer to use TCP instead of HTTP.
To do this from the AWS console (as it's laid out on 5/16/2015), go to your ElasticBeanstalk environment, choose "Configuration" on the left menu, under "Network Tier" there's a "Load Balancing" pane. Click its cog wheel, then you can change the load balancer protocol from http to tcp.

Resources