Hosting multiple asp.net core on ubuntu server with NGINX - asp.net-core

I'm getting crazy trying to host my 3 asp.net core services on a ubuntu server 22.04.
I managed to host correctly 2 static index.html pages following this tutorial: https://webdock.io/en/docs/how-guides/shared-hosting-multiple-websites/how-configure-nginx-to-serve-multiple-websites-single-vps
this is the response when I Curl http://{my ip address}/web2.webdock.io/ :
<html>
<title>web2.webdock.io</title>
<h1>Welcome to the web2.webdock.io with Nginx webserver.</h1>
</html>
using this configuration
server {
listen 80;
listen [::]:80;
root /var/www/html/web2.webdock.io;
index index.html index.htm;
server_name web2.webdock.io;
location / {
try_files $uri $uri/ =404;
}
}
When I try to do the same with my asp.net core api it doesn't work the same way. Here is my config file in the sites-enabled folder:
server {
listen 80;
server_name compliance;
location / {
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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
curl http://{my IP address}/compliance/ :
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
I'm totally lost. Just spent 6hours at work trying to get this working without any success.
And of course my api works perfectly in localhost:5001
Thanks for your help

Related

Nginx configuration to have served both static files sites than a reverse proxy for a .net core app

I installed Nginx on my Ubuntu 20.04 machine and I'm trying to serve a couple of simple static file along with a Asp.Net Core (MVC) app using Nginx as a reverse proxy.
What I would like to achieve:
http://example.com -> /var/www/StaticSiteFolder1/index.html
http://example.com/Site2 -> /var/www/StaticSiteFolder2/index.html
http://example.com/Site3 -> /var/www/StaticSiteFolder3/index.html
http://example.com/NetCoreApp -> get the netcore app running on http://localhost:5000
What I have done so far:
Configured all static sites with the following .conf file inside /etc/nginx/sites-enabled:
server {
listen 80;
listen [::]:80;
server_name myServer;
root /var/www/;
location / {
root /var/www/StaticSiteFolder1;
index index.html index.htm;
try_files $uri $uri/ =404;
}
location /StaticSiteFolder2 {
index index.html index.htm;
try_files $uri $uri/ =404;
}
location /StaticSiteFolder3 {
index index.html index.htm;
try_files $uri $uri/ =404;
}}
Created another .conf file for the reverse proxy, in the same directory:
server {
listen 80;
listen [::]:80;
server_name myServer;
root /var/www/;
location /NetCoreApp {
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-For $scheme;
}}
If I keep only the first one the static sites are served correctly.
If I leave only the second one changing "location /NetCoreApp" with "location /" and putting default_server in front listen 80 I have my netcore app correctly working on http://example.com.
I feel that it shouldn't be something so difficult but it's driving me crazy right now!
Thanks!

Reverse proxy nginx serves same website differently

I have set up nginx to reverse proxy, but I am having a weird problem. If I browse to
http://www.example.com/
The website displays correctly. However, if I browse to
example.com
I am sent to a different site!
This is part of my nginx config file:
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://localhost:8051;
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;
}
}
I got this to work, I think the problem is that browser cache.

Securing Nifi registry with nginx Error

I followed this tutorial to set up a secure version of Nifi registry: https://community.hortonworks.com/content/kbentry/170966/setting-up-a-secure-apache-nifi-registry.html
I am working on an ubuntu server. I do not have the possibility to generate the keychain and to access the graphical interface of nifi I use google chrome on my local machine (windows10). So I imported the p12 file in my browser. My nginx configuration file is as follows:
upstream container {
server 172.0.0.2:9000;
}
server {
listen 443 ssl;
ssl On;
ssl_certificate /etc/letsencrypt/live/sm/fullchain.pem; #/etc/nginx/ssl/fullchain.$
ssl_certificate_key /etc/letsencrypt/live/sm/privkey.pem; #/etc/nginx/ssl/privkey$
if ($ssl_protocol = "") {
rewrite ^ https://$host$request_uri? permanent; # optional, to force use of$
}
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php;
server_name workshop1.smart-mobility.alstom.com; # managed by Certbot
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location ~ /\.ht {
deny all; }
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
auth_basic "Restricted";auth_basic_user_file /etc/nginx/.htpasswd;
}
location /nifi-registry-api/ {
rewrite ^/nifi-registry-api/(.*) /nifi-registry-api/$1 break;
proxy_pass https://localhost:18443/nifi-registry;
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 /nifi-registry/ {
proxy_pass https://localhost:18443/nifi-registry;
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;
proxy_set_header X-ProxyScheme "https";
proxy_set_header X-ProxyHost $proxy_host;
proxy_set_header X-ProxiedEntitiesChain "<%{SSL_CLIENT_S_DN}>";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 1;
} }
When I log on to the nifi-registry page I have the following error: 502 Bad Gateway
can someone help me on this point please I do not find examples
Error log nginx :
*28739 SSL_do_handshake() failed (SSL: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate:SSL alert number 42) while SSL hands

WebRTC: How can I setup a signling-server and webserver together?

I am trying to transfer files between two devices (browsers) using WebRTC. I followed this GitHub repo to setup the signalmaster signaling-server, and it works fine. So, I put a simple index.html page in the same folder. But when I goto http://localhost:8888, it doesn't show the page. I then figure out that the Signaling server is not a webserver. So, I setup a webserver using Web server for chrome.
At this point I am confused about:
the need for signaling-server while having a webserver !! and
how I am going to use the signaling server if I am unable to load the webpage !!
in simple, why do I need the signaling-server for if I am already not using it ?! Also, how can I setup a signling-server and webserver together so that my page could load!
This gives a good overview of the role a signaling server plays with WebRTC:
https://www.html5rocks.com/en/tutorials/webrtc/infrastructure/
It's possible to use your current Webpage in combination with nodejs, php and nginx.
Nodejs and the signaling server are running in the background on port 8888 and with a reverse proxy you can call the webpage without a port in the url.
server {
listen 80 default;
server_name http://192.168.229.128;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
proxy_pass http://localhost:8888;
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 ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.io {
proxy_set_header X-Real-IP $remote_addr;
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_pass http://localhost:8888;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
In this case, socket.io is used, but you can remove it, if you want.

nginx+socket.io+ssl: WebSocket connection to 'ws://wechat.pageguy.tech/socket.io/?EIO=3&transport=websocket' failed: Unexpected response code: 302

I want to configure an node.js project using socket.io through nginx with ssl,But I failed,when I start it an error occours like this:
I spent a whole noon search and read documents but still can not figure out how to solve this..If anyone meet this problem before or have any idea about it please help me,thanks a lot.
This is my client side js code:
let socket = io.connect('//wechat.pageguy.tech/ws', {transports: ['websocket']});
This is nginx code:
server {
listen 443;
server_name wechat.pageguy.tech;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
ssl on;
ssl_certificate /etc/ssl/private/pageguy.crt;
ssl_certificate_key /etc/ssl/private/pageguy.key.unsecure;
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
proxy_pass http://localhost:3335;
}
location /ws/ {
proxy_pass http://localhost:3005;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
My express port is 3335,my socket.io port is 3005.Everything were fine before I added ssl in the nginx configuration file.
Nobody help me 555, but I solved problems by myself.
in client side js code:
let socket = io.connect('https//wechat.pageguy.tech/', {transports: ['websocket']});
in nginx configure file:
location /socket.io/(not /ws/ because its default value)