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

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.

Related

How can i configure my nginx to make my web app be accessed by both ip and domain name?

I want to be able to access my web app by by both ip and domain.with my current config i can only access either one depending with what i put on the server name property server_name: ip|domain
here is how my config is like
server {
server_name ip-address here;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_pass http://localhost:3000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Like #Amin commented, you could just add your IP as a "server name" like:
server_name 171.233.45.4 www.mydomain.com;
However this is discouraged as the main point of a server name directive is to have multiple domains or subdomains hosted at the same IP address. I.e. you want to serve two apps at 171.233.45.4 and NGINX can distinguish them because one has server_name my_app.com; and the other server_name potatos.com;.
If you want access by IP then that indicates you are running only one service on that address+port combination, meaning you do not need to specify a server name and instead could just configure DNS in the hosts file or in your router.
The simplest config would be:
server {
listen 80;
...
}
Where 80 is the service port number. Then, you would be able to access the server by IP and hostname if you configure your hosts files or some sort of DNS service to point your hostname to the server's IP.

Nginx redirect from one domain to dynamic domain?

I have two instances of nginx server running one with corporate ip and second with internal ip.I want a link from external nginx get redirected to internal nginx server and use external nginx as gateway. Also need to make sure that internal nginx running on dynamic IP
Tried to use variable for dynamic IP as shown in code snippet
location /route/(?<section>.+){
proxy_bind 172.31.*.*;
proxy_pass http://$section/single-table-view;
proxy_set_header Host $http_host;
}
You need to configure nginx as mentioned below:
If you want to redirect your External nginx to Internal nginx you should configure your External server like:
server {
listen 80;
listen [::]:80;
server_name domain_name;
location / {
proxy_pass http://InternalNginxIpAddress:PortYouWant;
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 each request from External nginx will be forwarded to Internal nginx, where your Internal nginx server is set as
proxy_pass http://localhost:PortYouWant;

How can I configure access from external ip to internal ip on GCP through nginx reverse proxy?

Can't connect to application through External IP.
I started gerrit code review application on GCP's vm instance(CentOS 7).
It works on http://localhost:8080 and I can't connect to it through external IP. Also I tried to create NGINX reverse proxy, but probably my configuration is wrong. By the way after installing NGINX, the starter page were shown on external ip.
# nginx configuration /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
auth_basic "Welcomme to Gerrit Code Review Site!";
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
gerrit.config
[httpd]
listenUrl = proxy-http://127.0.0.1:8080/
You use localhost as a server_name. I think that may cause conflict, because you connect to your server externally. You don't need server_name, cause you are going connect to your server by ip. And I recommend you enable logs in your nginx config. It will help you with bug fixing.
I recommend you try this config:
server {
listen 80;
access_log /var/log/nginx/gerrit_access.log;
error_log /var/log/nginx/gerrit_error.log;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
add a line in /etc/hosts
127.0.0.1 internal.domain
Update proxy config
proxy_pass http://internal.domain:8080;
It works with me

Proxy a websocket to hide the IP

I have a sub domain routed through cloudflare. They don't cover websockets unless it enterprise or maybe business depending on traffic.
So now when users visit the external site, it connects to my sub domain via a websocket with the url of my site being passed in their url.
e.g thridpartysite.com?ws=my.subdomain.com
But my IP is revealed and I am worried about DDoS.
I am using nginx and ubuntu 14.04. Is there anything I can do to mask the IP?
Here is my current nginx config
# Config
server {
listen 80;
listen [::]:80;
server_name my.subdomain.com www.my.subdomain.com;
location / {
proxy_pass http://MySubdomainIP:443;
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;
}
}
So it takes the app on 443 and proxies to 80 so I can route that through cloudflare but no websocket support means I need to reveal my IP which leaves me open to DDoS attacks.
Is there anything I can do at this point?
All plan levels support websoxkets.
https://support.cloudflare.com/hc/en-us/articles/200169466-Can-I-use-CloudFlare-with-WebSockets-

Dokku Port configuration problems EC2

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.

Resources