
Security News
curl Shuts Down Bug Bounty Program After Flood of AI Slop Reports
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.
nginx-vhosts
Advanced tools
Programmatically add or remove vhosts to a running Nginx instance.
To use this you should have your Nginx configuration file set up such that the http section has a include directive for all .conf files in a certain folder on your machine, e.g.:
http {
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
The machine configured with the configuration about would use either /etc/nginx/conf.d/ or /etc/nginx/sites-enabled/ as the confDir below. Note that the official Ubuntu PPA for Nginx has it configured this way by default.
See also:
var vhosts = require('nginx-vhosts')(opts, onStopStart)onStopStart is passed to and called from nginx-reload
var vhosts = require('nginx-vhosts')(opts, function running(isRunning) {
// isRunning is a boolean, true if nginx is running, false if it is not
// this function will get called whenever nginx stops or starts
// note: .reload() does not trigger this function, as nginx does not
// actually stop during a configuration reload
}
opts defaults to:
{
confDir: '/usr/local/etc/nginx/conf.d/',
pidLocation: '/var/run/nginx.pid'
}
vhosts.write(opts, cb)vhosts.write({
name: 'test',
port: '8080',
domain: 'test.local'
}, function(err, stdout, stderr) {
// err, stdout, and stderr from the nginx configuration reload
})
This writes a new configuration file to the configuration directory and then tells Nginx to reload its configuration. In the above example it would configure Nginx to proxy requests from test.local to localhost:8080
You can also supply your own config file:
vhosts.write({
name: 'test',
config: 'upstream foo { server 127.0.0.1:8080 } ...'
}, cb)
Note: it may take Nginx a few seconds to finish reloading the configuration after the callback is called.
vhosts.remove(name, cb)vhosts.remove('test', function(err, stdout, stderr) {
})
This removes a configuration file and tells Nginx to reload its configuration.
Note: it may take Nginx a few seconds to finish reloading the configuration after the callback is called.
There are integration tests available, provided you have the following things set up:
pid file in '/var/run/nginx.pid'include confs for http from /usr/local/etc/nginx/conf.d/test.local in your /etc/hosts as an entry for localhostnpm install
sudo npm test
FAQs
Programmatically add or remove vhosts to a running Nginx instance
We found that nginx-vhosts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.