How to connect to docker container with nginx

Hello friends, Starting with the package: https://railway.app/template/o3MbZe This is Nginx static site docker container. I have my own nging configuration I want to run but I really don't know how can I do this. Any help will be be welcomed πŸ™ Details: I have my backend running on railway and my site on vercel. My plan is to connect somehow my domain to the nginx service. Then from the nginx service proxy the network on port 80 and 443 to the vercel domain. And for port lets say 8000 to my backend on railway. Maybe my approach is fundamentally wrong and you can share how this should be done. Thank you!
74 Replies
Percy
Percyβ€’13mo ago
Project ID: e49f5ed7-ba90-4ebe-b635-e8604a8b2ebc
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
e49f5ed7-ba90-4ebe-b635-e8604a8b2ebc
Brody
Brodyβ€’13mo ago
what will this nginx config serve?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
More like a reverse proxy if I'm understanding properly
server {
listen 80;
server_name domain.com www.domain.com;

location / {
proxy_pass https://your-vercel-https-address;
}
}

server {
listen 443 ssl;
server_name domain.com www.domain.com;

ssl_certificate /path/to/ssl-certificate.crt;
ssl_certificate_key /path/to/ssl-certificate.key;

location / {
proxy_pass https://your-vercel-https-address;
}
}

server {
listen 8081;
server_name domain.com www.domain.com;

location / {
proxy_pass http://your-railway-address:8081;
}
}
server {
listen 80;
server_name domain.com www.domain.com;

location / {
proxy_pass https://your-vercel-https-address;
}
}

server {
listen 443 ssl;
server_name domain.com www.domain.com;

ssl_certificate /path/to/ssl-certificate.crt;
ssl_certificate_key /path/to/ssl-certificate.key;

location / {
proxy_pass https://your-vercel-https-address;
}
}

server {
listen 8081;
server_name domain.com www.domain.com;

location / {
proxy_pass http://your-railway-address:8081;
}
}
Something like this
Brody
Brodyβ€’13mo ago
what are you proxying to? just asking so I can understand better
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
I have railway with my Database + Redis + API and I want to host it on my domain on port 8000 lets say. And my website what is on vercel for now (in the future will be on railway to for consistency) should be on port 80 and 443 on my domain So if I type domain.com ill go to my vercel, but if i open postamn and type domain.com:8000/api I'll ask my api
Brody
Brodyβ€’13mo ago
you want to reverse proxy from the railway service to your site on vercel?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
If this is possible, if not I can transport my page to railway But that was the plan first. Is this understandable? I'm not sure if I explained it properly
Brody
Brodyβ€’13mo ago
no no I get what you wanna do, and I'll help you do it if you really want, but I just don't think that's the best idea what's the problem with having the frontend on vercel and the backend on Railway? vercel is made for frontend hosting, railway is geared more towards backend hosting vercel for frontend and railway for backend is a super common approach
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
I think it makes sense. But my problem is how can I connect it. That I have only one domain and different redirects on different ports ChatGPT helped me with creating the config file but I don't know how to put it into the container
Brody
Brodyβ€’13mo ago
in vercel you have the domain set to domain.com and on Railway you have the domain set to api.domain.com, then you call api.domain.com from the frontend
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
I don't have subdomains like api.domain.com I only have domain.com I can explain why I need backend to work from domain.com. This is because my mailchimp configuration requires that my emails are sent to the clients with the correct email domain. [email protected] => mailchimp requires it to be sent really from this domain. That is why I'm trying to do this with the ports
sam
samβ€’13mo ago
You'd have to run domain.com on the same host and then use a reverse proxy or similar to manage the routing of the traffic between Railway/Vercel
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
That is exacly what I want to do πŸŽ‰
The problem is I don't know how Could you help me? πŸ™
sam
samβ€’13mo ago
You should be able to call Mailchimp from server though? It shouldn't matter what domain you're on
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
It matters for mailchimp If i send an email from [email protected] and the @domain.com isn't the domain I've sent from then the email is being blocked
sam
samβ€’13mo ago
But there's not really any way for Mailchimp to know your API isn't at example.com Your API could be on api.example.com and Mailchimp wouldn't be any wiser unless there was RDNS on your IP
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
I don't know what RDNS is. I only know that I tried it and all my emails were blocked 😦
Brody
Brodyβ€’13mo ago
sam, there's no need to over complicate things if you have domain.com then there's nothing stopping you from creating an api.domain.com to use on railway
sam
samβ€’13mo ago
^
Brody
Brodyβ€’13mo ago
mail servers don't come into play here either Konrad, do you have your frontend working on vercel?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Yes
luna
lunaβ€’13mo ago
You do not need todo anything with hosting to send an email with them. Set the dns records mail chimp need and you’ll be good to go with sending emails.
Brody
Brodyβ€’13mo ago
Luna no over complicating things 😠
sam
samβ€’13mo ago
Unless they're using Mandrill
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
They use mandrill
Brody
Brodyβ€’13mo ago
we are no where near the need to talk about mail anything yet, everyone slow down
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Luna I've really tried It, with no luck
Brody
Brodyβ€’13mo ago
one small step at a time
luna
lunaβ€’13mo ago
It’s still just set DNS and be done with it… idk why this is being over complicated
sam
samβ€’13mo ago
yeah i think their problem is with getting the transactional email from their backend to mandrill
Brody
Brodyβ€’13mo ago
one topic at a time, we don't yet need to talk about mail servers yet Konrad, is your frontend accessable from a domain.com on vercel?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Yes it is for both http + https
Brody
Brodyβ€’13mo ago
okay and your backend, do you have it running on Railway?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Yes but with the normal Railway domain this random I mean my-domain.up.railway.app
Brody
Brodyβ€’13mo ago
gotcha, but does it work from the railway domain? (I lost signal)
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Excuse me, what do you exacly mean by that? If i type the my-domain.up.railway.app/api my backend (swagger) is run.
Brody
Brodyβ€’13mo ago
that's exactly what I mean, your backend, from the railway domain works as expected?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Yes
Brody
Brodyβ€’13mo ago
does your frontend on vercel make the api calls to the backend on railway just fine?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
I'm not asking my backend from my frontend. I have a mobile app. Frontend is just for users to read about the app. The mobile app calls the backend with the railway domain with no problem. Backend is working properly.
Brody
Brodyβ€’13mo ago
okay cool, I don't have any information about what your app is so forgive me for using such broad terms so would you say everything works, at least from a purely functional standpoint?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
I appreaciate any help, thank you for spending your time helping me Yes everything works fine
Brody
Brodyβ€’13mo ago
we have been saying domain.com, but would you mind telling me your actual domain?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
We prepare for release in upcoming months
Brody
Brodyβ€’13mo ago
and who did you buy the domain with?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Now we just use dummy template from astro NameCheap
Brody
Brodyβ€’13mo ago
did you know railway supports custom domains? you could have api.auri.chat connected to your railway service, and railway will handle SSL for you
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
I know that you can connect a domain to a service in railway. I did it for testing few times. I never tried with subdomains tho
Brody
Brodyβ€’13mo ago
subdomains are even easier what do you currently have in the domains section of the railway service
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
isn't that a problem with SSL cerificates? I think the wildcards one are expensive (or I'm wrong)
Brody
Brodyβ€’13mo ago
for api.auri.chat there is not wildcards involved, but even if there was SSL certs on wildcard domains are still completely free
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
No description
Brody
Brodyβ€’13mo ago
you have access to namecheap right?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
yes yes I've added the subdomain
Brody
Brodyβ€’13mo ago
and it gave you a cname, keep that cname in a notepad now just open up namecheap's advanced dns configuration menu and add a new cname type subdomain with that cname value railway gave you
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
done
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
No description
Brody
Brodyβ€’13mo ago
and can you show me what you've done for that subdomain in namecheap?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
No description
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
CNAME with api prefix and the link
Brody
Brodyβ€’13mo ago
okay looks like that new subdomain is all working, can you confirm that for me?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
It works but is not secure no https :/
Brody
Brodyβ€’13mo ago
works on https for me just fine, maybe clear your SSL cache?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
On incognito it works So probably cache, youre right
Brody
Brodyβ€’13mo ago
so you'd just have to update the domain that your app calls to your new api subdomain right?
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
No the mobile app could use the random railway domain. I needed it for the api to send emails. With the subdomain the maindrill doesn't want to send emails
No description
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
but there is hope let me check one thing
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
This will not work
No description
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
Mandrill requires from my now my @api.auri.chat email that I don't have to verivy the domain. This step is required I have to find another way to make this work Thank you for help Brody I have to go to sleep
Brody
Brodyβ€’13mo ago
I think you'd want to make a new domain, like mail.auri.chat and use that for all mail related setup
Konrad Pr0xy Night
Konrad Pr0xy Nightβ€’13mo ago
but the whole google businnes is connected to auri.chat yes I'll find a way thank you take care!
Brody
Brodyβ€’13mo ago
right but you'd definitely want to have mail.auri.chat for everything mail related you take care too!!
Want results from more Discord servers?
Add your server