#Deploying Medusa in AWS EC2

50 messages · Page 1 of 1 (latest)

junior ivy
#

I am having issue with deploying my medusa backend on EC2 instance. I have followed all steps as per this document.

https://pevey.com/medusa-server-on-ubuntu/2-configuring-the-server

The API & Admin is running fine when I check locally inside the instance. However, when I try to open admin in browser it shows "Invalid Host Header" error.

My nginx configuation is attached. Any insight will be much appreciated.

queen depot
#

hi @junior ivy you can try use https://nomodo.io/medusajs you get medusa in a few clicks without any troubles and hassle around. Your github repo with medusaJS could be easily connected as well. Check it out.

nomodo.io

Medusa, Shopify alternative in few seconds. No credit cards. No maintenance.

glad solstice
#

Awesome work Jan 🚀

queen depot
#

It would be great if you could test it out yourself as the medusa team and mention us as one of the deployment method in you doc. I can guarantee you that we are 10x better than Railway for the users.

stable dew
#

@junior ivy have you been able to get it to work?

junior ivy
#

@stable dew Not trying with AWS and Vercel

stable dew
#

@junior ivy I have Medusa running on an EC2 instance and it works just fine

junior ivy
#

@stable dew Let me check

#

@stable dew This is a bare-bone Node JS app. The problem here is that the API/BE is running locally and I tested this by using curl http://localhost:9000 inside my EC2 CMD.

The problem is when I open the URL as defined inside nginx. It throws error

Invalid host header

If you have any solution specific to the above error then it will be very helpful pls

#

@queen depot I am trying it now, will keep you posted

#

@queen depot Is there a way to deploy from an exisiting Git Repo. I am trying to connect to my repo, yet its still asking me to create a new one?

queen depot
#

@junior ivy it is not automatically possible right now. Primarly we offer to create a fresh medusaJS now. If you insist on connecting your own repo. It will takes a few days. What would you prefer?

junior ivy
#

@queen depot Let me know once ready...

#

In the meanwhile I keep looking for options

placid mural
#

This require proper server setup on AWS, i have deployed 4 medusajs projects on AWS from existing github code. If you want i can deploy for you.

stable dew
#

@junior ivy I followed the same for my medusaJS setup and it worked. did you map the url in your r53 to the public IP of the Ec2 instance? Also, what does your nginx configuration sytax say when you run sudo nginx -t

junior ivy
#

@stable dew I did not use Route 53 but I have added A record with the IP Address at Google Domain.

It is working fine for the /test URL which maps to a Hello World application hosted on the same instance.

#

sudo nginx -t says its good.

stable dew
#

@junior ivy I think everything seems correct. Can you start your application using pm2 and follow check pm2 logs

#

or you can also tail -f the logs to see what is going on maybe we can gain more insight into what might be the issue

junior ivy
#

@stable dew The error was due to the following:

Invalid Host header error on Browser in Nginx

The problem is that you have caused the Host header to be included twice.
proxy_set_header Host $host; include proxy_params;
Looking at the proxy_params file will show you that it was already set there. Setting it again causes the two values to be joined with a comma.
Inside that file you will find preset headers that will be used when you include that file. You do not need to repeat any of those lines in your own configuration.
ubuntu@vmtest-ubuntu2004:~$ cat /etc/nginx/proxy_params proxy_set_header Host $http_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;
You can remove your own additional proxy_set_header Host $host; from the configuration.

#

@stable dew Now I have installed it and it is running as https://

However, I find that the admin takes a lot of time to load. Any idea why?

#

The authentication also does not work.

stable dew
#

@junior ivy so you got your to work. if authentication isn't working you need to run yarn build and yarn build:admin

junior ivy
stable dew
#

@junior ivy start by setting your env variable to this. This is a bit relaxed but you can work your way up from there
ADMIN_CORS=/(https?://.+)/
STORE_CORS=/(https?://.+)/

junior ivy
#

@stable dew Thanks! Let me try...

junior ivy
#

@stable dew Still the same issue

stable dew
#

@indigo quail can you take a screenshot of your browser console messages? Also, can you inspect the logs on the server?

junior ivy
#

@stable dew Here it is

polar tide
queen depot
#

@polar tide yes, it is all included

polar tide
#

And it enclude both workers an Server

#

??

stable dew
#

@junior ivy I've had this same issue before, which had to do with the Cors setting. I can check it with you online on a call if you want.

queen depot
queen depot
junior ivy
#

@stable dew yes sure... in 30 mins we can have the call?

junior ivy
#

@stable dew Can you suggest me your good time so I can make myself available?

polar tide
queen depot
stable dew
#

@junior ivy apologies for the late response? are you available in about an hour?

polar tide
junior ivy
stable dew
#

@junior ivy open your DM