Giter Club home page Giter Club logo

nginx_ensite's Introduction

nginx_ensite and nginx_dissite for quick virtual host enabling and disabling

Description

This is a shell (Bash) script that replicates for nginx the Debian a2ensite and a2dissite for enabling and disabling sites as virtual hosts in Apache 2.2.

The original a2ensite and a2dissite is written in Perl. a2dissite is a symbolic link to a2ensite. Here I followed the same approach, i.e., nginx_dissite is a symbolic link to nginx_ensite.

Installation

Just drop the script and the symbolic link in /usr/sbin or other location appropriate for your system. Meaning: cp nginx_* /usr/sbin. That's it you're done.

Note that the script assumes a specific file system topology for your nginx configuration. Here's the rundown:

  1. All virtual hosts configuration files should be under /etc/nginx/sites-available. For example the virtual host foobar is configured through a file in /etc/nginx/sites-available.

  2. After running the script with foobar as argument: nginx_ensite foobar. A symbolic link /etc/nginx/sites-enabled/foobar -> /etc/nginx/sites-available/foobar is created. Note that if the /etc/nginx/sites-enabled directory doesn't exist the script creates it.

  3. The script invokes nginx -t to test if the configuration is correct. If the test fails no symbolic link is created and an error is signaled.

  4. If everything is correct now just reload nginx, in Debian based systems that means invoking /etc/init.d/nginx reload.

  5. Now point the browser to the newly configured host and everything should work properly assuming your configuration is sensible.

  6. To disable the site just run nginx_dissite foobar. Reload nginx to update the running environment.

Requirements

The script is written in Bash and uses what I believe to be some Bash specific idioms. I never tested it in other shells. You're welcomed to try it in any other shell. Please do tell me how it went.

It requires also awk. The original awk (usually called BWK awk) from Bell Labs will do if you don't have gawk (Gnu awk). IN OS X and *BSD the former is the default awk. The script should work in *BSD, OS X and GNU/Linux.

Command Completion

There's a Bash script for automatic completion of sites to be enabled and disabled located in the bash_completion.d directory.

To make use of it you should:

  1. Source the script to Bash by issuing either source nginx-ensite or . nginx-ensite.

  2. Now when you invoke nginx_ensite the sites under /etc/nginx/sites-available will appear as hypothesis for completion. For nginx_dissite you get all the sites listed in /etc/nginx/sites-enabled as possible completions.

  3. To get the completion script to be sourced upon login please copy it to /etc/bash_completion.d/ or whatever location your shell environment uses to place all the completion scripts. /etc/bash_completion.d/ is the location in Debian (hence also in Ubuntu) of Bash completion scripts.

Manual pages

Two UNIX manual pages are included in the man directory. They should be copied to a proper directory in your system. Something along the lines of /usr/share/man/man8 or /usr/local/share/man/man8.

Here's an online version of the manpage.

Security & Trust

The script is signed with my GPG key. Just do gpg --keyserver keys.gpg.net --recv-keys 4D722217. Verify by issuing gpg --verify nginx_ensite.sig.

Acknowledgments

Thanks to xufan6 for setting me on the path of the Bash completion script.

nginx_ensite's People

Contributors

cdzombak avatar dingens avatar luislobo avatar perusio avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.