nginx multiple domain configuration failed - nginx

502 bad gateway error, hmm I've no problem with my dns. I have a folder named 'app' and 'website' in my /home directory.
server {
listen 80;
server_name dashboard.abc.com;
location / {
root app;
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;
}
}
server {
listen 80;
server_name abc.com
location / {
root site;
index index.html index.htm;
}
}
Everything make sense here, not sure which part is causing the problem

Related

redirecting HTTP to HTTPS and proxy forwarding

So I'm trying to redirect port 80 to 443. I'm also trying to do a proxy forwarding to locahost:4000 with socket.io. are both correct or incorrect these are in nginx/sites-enabled/ap.kosherup. Not sure why the server { got cut off from rest of code. Also where would I add the security headers in the file? I am a noob.
server {
listen 80;
listen [::]:80;*
root /var/www/api.kosherup/html;
index index.html index.htm index.nginx-debian.html;
server_name api.kosherup www.api.kosherup;
return 301 https://api.kosherup.xyz$request_uri;
location /socket.io {
proxy_set_header Host $host;
proxy_pass http://localhost:4000/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /v1 {
proxy_pass http://localhost:4000/v1;
}
}
server {
listen 443;
listen [::]:443;
root /var/www/api.kosherup/html;
index index.html index.htm index.nginx-debian.html;
server_name api.kosherup www.api.kosherup;
location /socket.io {
proxy_set_header Host $host;
proxy_pass http://localhost:4000/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /v1 {
proxy_pass http://localhost:4000/v1;
}
}

Nginx configuration - https works but not http

I have an issue with a freshly configured Nginx setup on Debian 9.
My site loads fine using https, but I get a 404 Not Found when I access it using http.
I tried removing the ssl certificate, it works however i need the location /webex/receive in https and /ping and /mailgun in http.
See my edited down server block:
server {
listen 80;
listen 443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location /ping {
proxy_pass http://xx.xx.xx.xxx: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 /mailgun {
proxy_pass http://xx.xx.xx.xxx: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 /webex/receive {
proxy_pass http://xx.xx.xx.xxx: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;
}
}
All location (/ping, /mailgun and /webex/receive) work in https but I only want /webex/receive in https and the others locations /mailgun and /ping in http.
I found the solution
server {
listen 80;
listen [::]:80;
root /var/www/xx.xx.xx.xxx/html;
index index.html index.htm index.nginx-debian.html;
server_name xx.xx.xx.xxx www.xx.xx.xx.xxx;
location / {
try_files $uri $uri/ =404;
}
location /ping {
proxy_pass http://xx.xx.xx.xxx:3000;
}
location /mailgun {
proxy_pass http://xx.xx.xx.xxx:3000;
}
}
server {
listen 443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location /webex/receive {
proxy_pass http://xx.xx.xx.xxx:8080;
}
}

How to redirect NGINX to a websocket

NGINX - sitting on 10.10.10.1
LAMP - sitting on 172.168.1.1 , has phpwebsockets.This listens on http://172.168.1.1:8080 and having ws folder at http://172.168.1.1:8080/ws
Nginx supposed to forward request in this fashion.
NGINX ---> LAMP Websocket
http://10.10.10.1/randomstring/ --> https://10.10.10.1/randomstring/ --> http://172.168.1.1:8080
Currect /conf.d/internal.conf nginx config file is
server {
listen 80;
server_name 172.168.1.1;
return 301 https://$host$request_uri; #redirect to self with https
}
server {
listen 443 ssl;
server_name 172.168.1.1;
root /var/www/nginx/;
index index.html;
proxy_cache one;
location /ws {
proxy_pass http://172.168.1.1:8080;
# this magic is needed for WebSocket
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-Real-IP $remote_addr;
}
location / {
proxy_pass http://172.168.1.1:8080;
}
}
I am unable to forward to /randomstring , it works for without 'randomstring'.
Please add "/" at the end of proxy_pass
proxy_pass http://172.168.1.1:8080/;

Nginx config for subdomain and forum

I'm trying to configure nginx to do the following:
redirect example.com and www.example.com to my old website
www.example.com/forum or example.com/forum to forum webserver (ip)
any other subdomain to .example.com, reverse proxied to node.js
I know the following does not work, how should I configure?
server {
listen 80;
server_name www.example.com example.com;
location /forum {
proxy_pass http://<forum ip>/;
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;
}
return 301 $scheme://www.old-website.com;
}
server {
listen 80;
server_name ~^(.*)\.example\.com $;
location / {
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;
}
}
The naked return 301 will prevent the location /forum block from being considered. Try wrapping it inside a default location block:
location /forum {
...
}
location / {
return 301 $scheme://www.old-website.com;
}

403 forbidden for nginx locations

I have an nginx sites-enabled/default configuration:
server {
listen 80;
server_name localhost;
location / {
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;
}
location ~ /anotherroute {
alias /home/anotherroute/public;
index index.html;
}
}
When I access http://myipaddress/anotherroute it works fine but when I do http://myipaddress/anotherroute/yetanotherroute it comes back as 403 forbidden.
How can I fix this?
Possibly your folder yetanotherroute is existed, make sure you have files index.php or index.html already
Otherwise you should specified a file name such as: http://myipaddress/anotherroute/yetanotherroute/somefile.php

Resources