Dokku Port configuration problems EC2 - nginx

I currently trying to deploy my App on a EC2 Instance using Dokku and my first impression is that it's really amazing. Still I have some problems relating the configuration of my App that it's reachable via port 80 and not to the docker container port.
So for instance when i try to reach my app it's reachable under:
http://recipeapp.xxx.de:49169/
but not under
http://recipeapp.xxx.de/
My VHOST config looks like this:
xxx.de
The nginx.conf of the app is generated as the following:
upstream recipeapp { server 127.0.0.1:49169; }
server {
listen [::]:80;
listen 80;
server_name recipeapp.xxx.de;
location / {
proxy_pass http://recipeapp;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
}
I add my remote with:
git remote add appstore dokku#xxx:recipeapp
And push it with:
git push appstore master
So what am I doing wrong? I now trying it for days to make it running correct but I don't see any possibilities any more.

Doublecheck the contents of /home/dokku/VHOST as root. The file should contain a single line, namely "xxx.de".
If the file is absent, touch /home/dokku/VHOST and enter the line.
Also keep in mind that you need to configure the DNS settings for xxx.de; A record for xxx.de pointing to EC2 instance and A record for *.xxx.de also pointing to EC2 instance.
Hope this helps.

Related

Nginx: Should I choose default or mydomain.conf configuration to serve a single domain in a server?

I am new Nginx. Currently, I configured my domain to be served by Nginx on the default configuration as follows and it is working.
sudo nano /etc/nginx/sites-available/default
Default configuration:
server {
listen 80;
server_name uidcenterkl.my *.uidcenterkl.my;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
However, I learnt that I need to create domain specific directive such as mywebiste.com.conf as follows:
sudo nano /etc/nginx/sites-available/mywebiste.com.conf
Question:
What should I choose, default or mywesbite.com.conf to serve a single domain? And if I went with mywebsite.com.conf, how to deactivate default configuration so that it does not cause conflict.
You may actually not need to set up domain specific directive to serve a single domain. default directive should work fine for you.
And if you choose to use mywesbite.com.conf, all you need to do to disable default is to delete it from inside sites-enabled directory
After creating your mywesbite.com.conf feel free to delete the default.conf by running this command from your sites-enabled dirctory:
sudo rm ../sites-enabled/default.conf
Don't forget to restart your nginx after that command
systemctl restart nginx

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 docker reverse proxy with http/https and tcp (ssh)

I have a docker container with nginx (v. 1.17, no plus version) set up as a reverse-proxy (http/https) to other docker containers and machines.
An example configuration I have is the following:
server {
resolver 127.0.0.11;
listen 443 ssl;
server_name gitlab.mydomain.com;
location / {
proxy_pass http://gitlab:30000;
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;
}
}
And this works perfectly.
What is missing is the configuration for accessing gitlab (and other machines I need) trough SSH.
I saw in some other questions that you can use streams and other new nginx features, but I didn't quite get how to embed this with my current configuration.
Can someone help me with this settings? How can we combine http/https reverse proxy with ssh reverse-proxy?

Nginx subdomain config for Gunicorn server

I have two servers running on a DigitalOcean droplet. One is a Django/Wagtail application served with Gunicorn (used as a headless CMS), and the other is a SSR Nuxt.js app (front-end). Using the following nginx configuration I’ve made the Nuxt app available at example.com (works great), and now I’m trying to make my Django/Wagtail application available at the subdomain cms.example.com. (I’ve modified my local hosts file so the domain example.com actually functions)
/etc/nginx/sites-available/default
server {
listen 80;
listen [::]:80;
server_name example.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;
}
}
server {
listen 80;
listen [::]:80;
server_name cms.example.com;
location / {
include proxy_params;
proxy_pass http://unix:/home/thomas/daweb/cms/cms.sock;
}
}
/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;
Result from curl --unix-socket /home/thomas/daweb/cms/cms.sock cms.example.com is html of the default Wagtail landing page, no errors.
However navigating to cms.example.com just gives me a connection error. If I swap the two, I can see the Wagtail interface at example.com, so I know they’re both working. However, I can’t seem to figure out how to configure a subdomain and I struggle to understand the nginx documentation. Also similar questions about configuring subdomains are usually about making static files available, not listening to active ports.
One extra layer of trouble is that the Wagtail CMS is accessible at /admin of its server root, so I’d like to make that page appear at cms.example.com rather than having to navigate to cms.example.com/admin. Any help would be greatly appreciated!
Check what is contained in /etc/nginx/proxy_params. I would expect something like this:
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;
Also, to be sure Gunicorn is working correctly, try:
curl --unix-socket /home/thomas/daweb/cms/cms.sock cms.example.com

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