asp.net core multiple apps on nginx - nginx

I have been working to get a couple asp.net core webapps running on EC2 ubuntu instance using nginx and supervisor. I am successful in running one app at a time and by simply swapping my port in my nginx setting and reloading I can swap between the running .netcore apps running on 5000 and 5001. I cannot seem to figure out the nginx settings to make them both work at a path, ie: hostname/app1, hostname/app2.
Here is my Nginx Config. Could anyone point to something I have done wrong? My supervisor is running both apps I can verify that by looking at the logs and also changing the port in the default location "/".
server {
listen 80 default_server;
listen [::]:80 default_server;
# 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;
# }
location /app1 {
rewrite ^/app1(.*) /$1 break;
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;
}
location /app2{
rewrite ^/app2(.*) /$1 break;
proxy_pass http://localhost:5001;
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;
}
}
I do not have a default route simple because I don't have anything to put there yet.

Looks like the solution was trailing slashes on the location and proxypass
server {
listen 80 default_server;
listen [::]:80 default_server;
# 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;
# }
location /app1/ {
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;
}
location /app2/ {
proxy_pass http://localhost:5001/;
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;
}
}

Related

nginx redirect rule, example.com/gaming/postName to g.example.com/postName

I am trying to make 301 redirect rule because I moved my website domain.
My blog was running on
example.com/gaming
and posts are like this
example.com/gaming/postName
I want to rewrite it with a rule to be
G.example.com/postName
basically changing example.com/gaming -> g.example.com
There are many solutions for this problem and here's the one which I use.
server {
listen 80;
server_name example.com;
location /gaming {
proxy_pass https://YOUR_APP_IP: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;
}
location / {
proxy_pass https://YOUR_APP_IP: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;
}
}
Here, keep YOUR_APP_IP as 127.0.0.1 if you're running on the same machine. else use the IP of the machine where your application is running.
This will route all the /gaming routes to default route.

Ngnix: Multiple Websites Using a Shared IP on a Server with Multiple IP Adress

I am deploying multiple websites to an Ubuntu server equipped with Nginx. I also use the proxy_pass feature to pass the traffic to the service.
The problem is whichever websites is set on Nginx first, all incoming traffics are rerouted to.
I created 3 different .conf files in /etc/nginx/conf and here is the details for each:
subdomain1.conf
server {
listen <the second ip>:80;
server_name subdomain1.mydomain.com;
location / {
proxy_pass http://127.0.0.1:11111;
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;
}
}
subdomain2.conf
server {
listen <the second ip>:80;
server_name subdomain2.mydomain.com;
location / {
proxy_pass http://127.0.0.1:22222;
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;
}
}
subdomain3.conf
server {
listen <the second ip>:80;
server_name subdomain3.mydomain.com;
location / {
proxy_pass http://127.0.0.1:33333;
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;
}
}
Finally, I reload Nginx using the following command line:
sudo nginx -s reload
However, all incoming traffics for other subdomains (subdomain2 and subdomain3) are somehow passed to subdomain1. What I have noted so far is whichever set first, all incoming traffics are bound to it.

nginx gives 400 bad request for urls with whitespace

I have nginx proxying requests to a node.js web app in the backend on a Ubuntu box. For requests to api.example.com with whitespace in the url get a 400 bad request error. Think the problem line of code is:
proxy_pass http://127.0.0.1:3002$uri$is_args$query_string;
however not sure how to rewrite it.
This is how the site configuration at /etc/nginx/sites-available/default looks:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1: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;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:3002$uri$is_args$query_string;
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;
}

How to config NGINX port redirection?RStudio, Jupyter and JupyterLab

I have jupyter running on port 8000 and jupyter lab running on 8888. Nginx configuration looks like (server listens on port 80):
location /julia/ {
proxy_pass http://localhost:8000;
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 Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
access_log /var/log/nginx/julia-access.log;
error_log /var/log/nginx/julia-error.log;
}
and
location /jupyterlab/ {
proxy_pass http://localhost:8888;
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 Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
access_log /var/log/nginx/jlab-access.log;
error_log /var/log/nginx/jlab-error.log;
}
/julia works fine
/jupyterlab doesn't, but server:8888 works fine.
Why? What to change?
On 8787 I've got RStudio, with nginx config:
location / {
proxy_pass http://localhost:8787;
proxy_redirect http://localhost:8787/ $scheme://$host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
access_log /var/log/nginx/rstudio-access.log;
error_log /var/log/nginx/rstudio-error.log;
}
Maybe I should remove Jupyter (/julia/) and leave only JupyterLab?

Asp.Net Core 2 SignalR Ubuntu Xamarin Android

I have deployed Asp.Net Core 2 website on ubuntu with Nginx as a reverse proxy. The website works but SignalR doesn't. Same build work locally in IIS-Express. Getting following error in logs,
Terminating Long Polling connection by sending 204 response.
Following nginx configuration I am using,
server {
listen 80;
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;
}
}
I am accessing the server from Xamarin Android.
What can be the issue? Any help would be great. Thanks in advance.
You should change you config to add additional path which needs the Upgrade header
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /socket/path/ {
proxy_pass http://localhost:5000;
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;
}
}

Resources