A cli tool to quickly create and manage nginx server blocks.
https://up.js.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.2 KiB
34 lines
1.2 KiB
var fs = require('fs-extra');
|
|
var shell = require('shelljs');
|
|
|
|
var npath = require('../utils/nginxPath');
|
|
var conf = require('../utils/nginxConf');
|
|
var nginxReload = require('../utils/nginxReload');
|
|
|
|
var EOL = require('os').EOL; // \n if used on Linux, \r\n if used on Windows.
|
|
|
|
function createProxyServer(domain, inPort, outPort) {
|
|
fs.outputFileSync((conf(npath.availableSites(), domain, outPort)),
|
|
"server {" + EOL +
|
|
" listen " + outPort + ";" + EOL +
|
|
" listen [::]:" + outPort + ";" + EOL +
|
|
" index index.html index.htm;" + EOL +
|
|
"" + EOL +
|
|
" server_name " + domain + ";" + EOL +
|
|
" location / {" + EOL +
|
|
" proxy_pass http://localhost:" + inPort + ";" + EOL +
|
|
" proxy_http_version 1.1;" + EOL +
|
|
" proxy_set_header Upgrade $http_upgrade;" + EOL +
|
|
" proxy_set_header Connection 'upgrade';" + EOL +
|
|
" proxy_set_header Host $host;" + EOL +
|
|
" proxy_cache_bypass $http_upgrade;" + EOL +
|
|
" }" + EOL +
|
|
"}"
|
|
);
|
|
shell.mkdir('-p', npath.enabledSites()); // Creates directory if doesn't exist
|
|
shell.ln('-sf', conf(npath.availableSites(), domain, outPort), conf(npath.enabledSites(), domain, outPort)); // Symlink the conf file from sites-available to sites-enabled
|
|
|
|
nginxReload();
|
|
}
|
|
|
|
module.exports = createProxyServer;
|