Nodejs with reverser proxy - nginx

I'm currently using NodeJs over Nginx for hosting a website, since I've already realized the port conflict of Nginx, I already change the configure file and I can access localhost now.
But the problem is the website is no longer the same as the one hosted on port 3000(which I set the NodeJs source to listen)
It is really struggling and I really do wish someone can get me a solution.
The configure code is list below
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
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;
}

Related

NGINX does not serve js and css files while serving html

I installed NGINX as a reverse proxy on ubunty. However after installation it turned out that NGINX does not serve css and js files while still serving html files.
I have the following configuration in /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
location / {
proxy_pass http://localhost:5000/;
include /etc/nginx/mime.types;
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;
try_files $uri $uri/ =404;
}

Can't get Pocketbase running behind Ngnix as a reverse proxy

I want to use Pocketbase behind Ngnix as a reverse proxy on my Ubuntu-VPS. I followed the documentation on https://pocketbase.io/docs/going-to-production/.
I wanted to put pocketbase to /api/. When i try to connect to the pocketbase admin panel the browser shows some 404 and a ContentSecurityPolicy Error. It looks like this:
It also seems to be that some HTML is loaded from Pocketbase.
This is my current ngnix config (i replaced my domain with test.com)
server {
listen 80;
listen 443 ssl;
server_name test.com;
ssl_certificate /etc/letsencrypt/live/test.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/test.com/privkey.pem;
location / {
try_files $uri $uri/ /index.html;
root /var/www/html;
index index.html;
}
location /api/ {
# check http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive
proxy_set_header Connection '';
proxy_http_version 1.1;
proxy_read_timeout 360s;
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-Proto $scheme;
proxy_pass http://127.0.0.1:8090;
}
}
Pocketbase is started with the default localhost settings on the VPS.
I can even access pocketbase over http://127.0.0.1:8090/api/ when i'm connected via SSH in VS Code and see the requests in the log. (i am surprised that this is even possible. At first i tought i had pocketbase running on my local machine but when i killed the backend on my vps i couldn't access it anymore)
I hope that somebody can help me out as i can't find much about this in the internet.
Problem solved. It works when append a / to the address at the proxy_pass directive
proxy_pass http://127.0.0.1:8090/;

Appwrite with Nginx

I installed Appwrite on an debian-server.
The https-port for Appwrite is 444 (443 was already used). Nginx redirects my subdomain to this port.
I have a custom SSL-certificate which is working for this domain and subdomains. I can open the appwrite via the subdomain but when I click "Sign Up" to create a root account for appwrite, I get the following Error:
Invalid Origin. Register your new client (appwrite.domain.de) as a
new Web platform on your project console dashboard
First I thought I have to set proxy_set_header Host $host; in the server-config, but then I am not able to open Appwrite... instead I get the Error
{"message":"Error: Server Error","code":500,"version":"1.0.1"}
Does someone has another idea or already fixed the same problem?
This is my Server-configuration in Nginx:
server {
server_name appwrite.domain.de;
location / {
proxy_pass https://localhost:444;
}
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/domain.de_ssl_certificate.cer;
ssl_certificate_key /etc/nginx/ssl/domain.de_private_key.key;
}
server {
listen 80;
server_name domain.de
www.domain.de
;
return 301 https://$host$request_uri;
}
server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/domain.de_ssl_certificate.cer;
ssl_certificate_key /etc/nginx/ssl/domain.de_private_key.key;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name domain.de
www.domain.de
;
location / {
try_files $uri $uri/ =404;
}
Thanks for the help ;)
You're right, you need to include the proxy_set_header Host $host; directive. You might also want to include the following under server:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
and the following under location:
add_header X-Served-By $host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $port;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $forward_scheme://$server:$port$request_uri;
If you're seeing a 500 error, it would be best to check the docker logs for the appwrite container to see what the problem is.
On a side note, if you're looking for an easier way to manage Nginx, I highly recommend Nginx Proxy Manager (NPM). I use NPM in front of my Appwrite.

Nginx doesn't load css on Asp.net core in raspberry

First of all, thanks for reading my thread. Second, sorry for my English.
I'm trying to run an Asp.net core application in a raspberry but still facing some problems when proxying with nginx.
Basically I follow these tutorials to configure my workplace and export my project to arm, the only difference is that I've created a MVC application instead a simple Hello World:
http://www.protosystem.net/blog/aspnet-core-on-raspberry-pi/
http://www.protosystem.net/blog/aspnet-core-hello-world-on-raspberry-pi/
The problem starts when I execute the app. For default, it runs on port 5000, but when nginx do the proxy for port 80 it doesn't load the css.min, javascrip files and the Home directory according to the image below:
Follow the nginx configuration below:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /www/mywebsite;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
try_files $uri $uri/ =404;
}}
Per my comment I would suggest removing the try_files directive like so:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /www/mywebsite;
index index.html index.htm index.nginx-debian.html;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}}
}

Configure Nginx to serve a node js app from a location within root directory

I am trying to serve a Node JS app alongside some static sites that are already functioning and only serving static content (/insta-app is one of the apps, there is another nginx file with another server block for the other ones which sit on different subdomains). I am successfuly getting the server.js app when I navigate to the URL /nodejsapp. The problem is that all the static content the app requires does not get served and comes up as a 404 (images, js files and css). I wrote a location block for nodejsapp/dist where the static content exists but this did not fix the problem. The content is being requested by a handlebars template that gets successfully called and is sitting in a views folder in the root. I am running the whole thing on an ubuntu server, and the node app is running through pm2 which is working fine when I request curl localhost:3000. How can I get the static content into the server?
Nginx server block:
server {
listen 443 ssl default_server;
root /var/www;
index index.html index.htm server.js;
server_name uat.com www.uat.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/uat.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/uat.com/privkey.pem;
location / {
try_files $uri $uri/ =404;
}
location ~ /.well-known{
allow all;
}
location /insta-app{
alias /var/www/insta-app/html;
allow all;
}
location /nodeJsApp{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
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 $proxy_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
# attempt to serve the static content of the app
location /nodeJsApp/dist{
root /var/www/sydney-sevens/dist;
try_files $uri $uri/ =404;
}
}

Resources