How to config Nginx server multiple applications on one domain - nginx-reverse-proxy

I have 3 applications on one server
A: a bootstrap landing page, in /var/www/aaa
B: a react project, in /var/www/bbb
C: a h5 project, in /var/www/ccc
I want:
https://example.com goto A
https://example.com/home goto B (not https://example.com/home/xxx)
https://example.com/square goto C
I knew there are 3 way to do this:
One: by subdomain, but A,B,C are belong to a same big project, worry cross domain problem.
Two: by location, I did some search and tried, found it require url like https://example.com/home/index.xxx, but my project url will be https://example.com/home?event=xxx
Three: proxy_pass, I tried 3 days but failed, appreciate for any help.
main.conf
server {
listen 443 ssl http2;
server_name example.com localhost;
ssl_certificate /etc/ssl/certs/example.crt;
ssl_certificate_key /etc/ssl/example.key;
location /square/ {
proxy_pass http://localhost:83/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /home/ {
proxy_pass http://localhost:82/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://localhost:81/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
a.conf
server {
listen 81;
location / {
alias /var/www/aaa/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
b.conf
server {
listen 82;
location / {
alias /var/www/bbb/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
c.conf
server {
listen 83;
location / {
alias /var/www/ccc/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}

Related

How to pass query to api server located in nginx proxy_pass?

Proxy_passed nginx through the trailing path to api-server.com using rewrite.
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/api(.*)$ $1?$args break;
proxy_pass http://api-server.com;
}
}
localhost/api/ -> api-server.com/
This URL worked fine.
However, in the code above, the trailing path was not passed and only a not_found error occurred.
localhost/api/goods/info?code=1234 -> api-server.com/goods/info?code=1234
I tried something like http://api-server.com/$args, but it only gave me a not_found error and couldn't pass it on.
(Find that trailing path localhost.)
I am very curious if there is a way to do it.

Nginx proxy for vue and fastapi

I am trying to deploy my app with vue.js as frontend and fastapi as backend. But I am having issue when deploy the app on the cloud. I have nginx configure like below.
I am binding backend to port 8080 and frontend to 8000. But with this configuration, I can only see my frontend page. The backend api is not respond. Can anyone show me how to fix it?
server {
listen 80;
server_name example.com;
charset utf-8;
root vis/dist;
index index.html index.htm;
location /api/ {
proxy_pass http://127.0.0.1:8000;
}
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect off;
proxy_connect_timeout 90s;
proxy_read_timeout 90s;
proxy_send_timeout 90s;
}
error_log /var/log/nginx/vue-app-error.log;
access_log /var/log/nginx/vue-app-access.log;
}

Nginx config for vue app and express server

I have a ubuntu server on which I have a vue app and am trying to add an express app. Everything is working correctly in my vue app but the only route that works for my express location is the index route at /api.
here is my nginx.conf:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/vue/family-showdown/client/dist;
index index.html index.htm index.nginx-debian.html;
server_name _;
error_page 404 /;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://localhost:8080/;
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 / {
root /var/www/html/vue/family-showdown/client/dist;
}
}
in my express app.js I have:
app.use('/', _index["default"]);
app.use('/users', _users["default"]);
Navigating to /api works correctly so I would expect that navigating to /api/users should work but instead I get a 404 that says Cannot GET //users
there is no any location in your nginx configuration for /users path. you can try this configuration.
location / {
root /var/www/html/vue/family-showdown/client/dist;
index index.html;
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://localhost:8080;
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;
}
location /users/ {
proxy_pass http://localhost:8080;
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;
}
and delete these configurations
root /var/www/html/vue/family-showdown/client/dist;
index index.html index.htm index.nginx-debian.html;
server_name _;
error_page 404 /;
location / {
root /var/www/html/vue/family-showdown/client/dist;
}

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.