Skip to content

Instantly share code, notes, and snippets.

@jsupa
Last active February 27, 2022 13:58
Show Gist options
  • Save jsupa/8d33e30654863196d71156a757df5451 to your computer and use it in GitHub Desktop.
Save jsupa/8d33e30654863196d71156a757df5451 to your computer and use it in GitHub Desktop.
How to make node js express app what show data by subdomain what reversed by nginx
  • add domain DNS record * A server-ip
  • on server $ nano /etc/nginx/conf.d/app.conf
	server {
		add_header Access-Control-Allow-Origin *;
		listen 443 ssl;
		server_name *.domain.example;
		error_page 502 /502.html;
		
		location / {
			proxy_pass http://localhost:8198;
        		proxy_set_header Host $host;
		}

		location /502.html {
			root /var/www/html;
		}

		ssl_certificate_key /etc/letsencrypt/live/domain.example/privkey.pem;
		ssl_certificate /etc/letsencrypt/live/domain.example/fullchain.pem;
	}	
  • make example express app $ nano ~/app.js $ npm i express
const express = require('express');
const app = express();

app.all('*', (req, res) => {
    console.log(req.subdomains);
    res.send("ok");
})

app.listen(8198);

$ node ~/app.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment