GithubHelp home page GithubHelp logo

apostrophecms / mechanic Goto Github PK

View Code? Open in Web Editor NEW
167.0 19.0 28.0 487 KB

Command-line tool to manage nginx-powered proxies for node apps. Static file delivery, load balancing, HTTPS, all that jazz with a clean interface.

JavaScript 100.00%

mechanic's Introduction

CircleCI

mechanic

Purpose

nginx is a popular reverse proxy server among node developers. It's common to set up one or more node apps listening on high-numbered ports and use nginx virtual hosting and reverse proxy features to pass traffic to node. nginx can also serve static files better than node can, and it has battle-tested round-robin load balancing features.

We've boiled down our favorite configuration recipes for nginx to a simple utility that takes care of spinning up and shutting down proxies for new node sites on a server. It can also handle load balancing, canonical redirects, direct delivery of static files and https configuration. It takes the place of manually editing nginx configuration files.

Install

Step One: install nginx on your Linux server.

Under Ubuntu Linux that would be:

apt-get install nginx

Make sure Apache isn't in the way, already listening on port 80. Remove it really, really thoroughly. Or reconfigure it for an alternate port, like 9898, and set it up as a fallback as described below.

Step Two:

npm install -g mechanic

NOTE: mechanic will reconfigure nginx after each command given to it. A strong effort is made not to mess up other uses of nginx. Mechanic's nginx configuration output is written to /etc/nginx/conf.d/mechanic.conf, where both Debian-flavored and Red Hat-flavored Linux will load it. No other nginx configuration files are touched. You can change the folder where mechanic.conf is written, see below.

Step Three:

Go nuts.

Let's add a single proxy that talks to one node process, which is listening on port 3000 on the same server (localhost):

All commands must be run as root.

Adding a site

mechanic add mysite --host=mysite.com --backends=3000

Replace mysite with a good "shortname" for your site— letters and numbers and underscores only, no leading digits.

mechanic will reconfigure and restart nginx as you go along and remember everything you've asked it to include.

Aliases: alternate hostnames

Next we decide we want some aliases: other hostnames that deliver the same content. It's common to do this in the pre-launch period. With the update command we can add new options to a site without starting from scratch:

mechanic update mysite --aliases=www.mysite.com,mysite.temporary.com

Canonicalization: redirecting to the "real name"

In production, it's better to redirect traffic so that everyone sees the same domain. Let's start redirecting from our aliases rather than keeping them in the address bar:

mechanic update mysite --canonical=true

Setting a default site

We've realized this site should be the default site for the entire server. If a request arrives with a hostname that doesn't match any --host or --aliases list, it should always go to this site, redirecting first if the site is canonical. We can do that with default:

mechanic update mysite --default=true

Warning: If your server came with a default website already configured, like the server block that appears in /etc/nginx/nginx.conf in CentOS 7, you will need to comment that out to use this feature. mechanic does not mess with the rest of your nginx settings, that is up to you.

Fast static file delivery

Let's score a big performance win by serving our static files directly with nginx. This is simple: if a file matching the URL exists, nginx will serve it directly. Otherwise the request is still sent to node. All we have to do is tell nginx where our static files live.

mechanic update mysite --static=/opt/stagecoach/apps/mysite/current/public

Browsers will cache the static files for up to 7 days. That's a good thing, but if you use this feature make sure any dynamically generated files have new filenames on each new deployment.

Serving index.html for bare directories

When using --static, you can optionally enable serving index.html automatically when a URL matches a directory name by using the --autoindex option.

mechanic update mysite --autoindex

As with all boolean options you can change your mind later:

mechanic update mysite --autoindex=false

In a typical proxy configuration, this makes it possible to use an index.html file as a cached static version of a resource with a "pretty URL" like /people that would normally hit your back end server.

Static websites

Although static websites will never be a primary use case for mechanic, you can set up a perfectly reasonable static webserver like this:

mechanic add mysite --host=mysite.com --static=/var/www/html/mysite --autoindex

The backends option is no longer mandatory when --static is present.

If you have more elaborate use cases that don't involve a reverse proxy, you should really create a separate nginx configuration file for that site.

Load balancing

Traffic is surging, so we've set up four node processes to take advantage of four cores. They are listening on ports 3000, 3001, 3002 and 3003. Let's tell nginx to distribute traffic to all of them:

mechanic update mysite --backends=3000,3001,3002,3003

Across two servers

This time we want to load-balance between two separate back-end servers, each of which is listening on two ports:

mechanic update mysite --backends=192.168.1.2:3000,192.168.1.2:3001,192.168.1.3:3000,192.168.1.3:3001

You can use hostnames too.

Secure backends

If you're proxying to a remote server, it's a good idea to enable HTTPS there too, so your connection is secure end-to-end. If you use the https-upstream option, nginx will make requests to your backends using SSL.

mechanic update mysite --https-upstream

Note that this can introduce a significant performance overhead, as nginx will need to validate certificates and encrypt the connection with the backend.

Backends for certain URL paths only

You can configure a backend exclusively for with a certain path prefix:

mechanic update mysite --backends=3000,3001:/ci-server

This is also supported for backends not running on the same computer:

mechanic update mysite --backends=192.168.1.2:3000,192.168.1.2:4000/ci-server

The prefix is included in the URL passed through to the backend.

If such a backend is present, matching requests are sent only to it. You may have more than one for the same path, in which case they are load balanced by nginx in the usual way.

This feature is useful when microservices share a single hostname.

Secure sites

Now we've added ecommerce and we need a secure site:

mechanic update mysite --https=true

Now nginx will serve the site with https (as well as http) and look for mysite.cer and mysite.key in the folder /etc/nginx/certs.

See the nginx docs on how to handle intermediate certificates.

Redirecting to the secure site

Next we decide we want the site to be secure all the time, redirecting any traffic that arrives at the insecure site:

mechanic update mysite --https=true --redirect-to-https=true

Redirecting to another site

We can also redirect all traffic to a different site. To redirect 100% of the traffic to one specific URL, use --redirect:

mechanic update mysite --redirect=https://example.com

To instead append the rest of the original URL to a redirected domain, use --redirect-full:

mechanic update mysite --redirect-full=https://example.com

Setting --redirect clears --redirect-full, and vice versa.

Enabling HTTP/2

We can enable HTTP/2 by setting http2 to true:

mechanic set true

Disabling HTTP/2

We can disable HTTP/2 by setting http2 to an empty string:

mechanic set ''

Permanent and Temporary Redirects

All redirects are temporary by default. To make redirects permanent (301), use --permanent=true. To go back to a temporary (302) redirect, use --permanent=false.

mechanic update mysite --permanent=true

Shutting off HTTPS

Now we've decided we don't want ecommerce anymore. Let's shut that off:

mechanic update mysite --https=false

Removing a site

Now let's remove the site completely:

mechanic remove mysite

Disabling options

You can disable any previously set option, such as static, by setting it to false or the empty string.

Falling back to Apache

If you also want to serve some content with Apache on the same server, first configure Apache to listen on port 9898 instead of 80, then set up a default site for mechanic that forwards traffic there:

mechanic add apache --host=dummy --backends=9898 --default=true

We still need a host setting even for a default site (TODO: remove this requirement).

Apache doesn't have to be your default. You could also use --host and set up individual sites to be forwarded to Apache.

Global options

There are a few global options you might want to change. Here's how. The values shown are the defaults.

conf: nginx configuration file location

mechanic set conf /etc/nginx/conf.d

This is the folder where the mechanic.conf nginx configuration file will be created. Note that both Red Hat and Debian-flavored Linux load everything in this folder by default.

restart: nginx restart command

mechanic set restart "nginx -s reload"

The command to restart nginx.

Don't forget the quotes if spaces are present. That's just how the shell works, but it bears repeating.

logs: webserver log file folder

mechanic set logs /var/log/nginx

If this isn't where you want your nginx access and error log files for each site, change the setting.

bind: bind address

mechanic set bind "*"

By default, mechanic tells nginx to accept traffic on all IP addresses assigned to the server. (* means "everything.") If this isn't what you want, set a specific ip address with bind.

_If you reset this setting to _ make sure you quote it, so the shell doesn't give you a list of filenames.*

Enabling websockets

By default, nginx does not proxy websockets. You can enable this by passing the --websockets flag:

mechanic update mysite --websockets

This enables websockets proxying per the nginx documentation by setting the HTTP version for the proxy to 1.1 and setting the Upgrade header.

As with other boolean flags you can turn this off again with --websockets=false.

template: custom nginx template file

mechanic set template /etc/mechanic/custom.conf

You don't have to use our nginx configuration template.

Take a look at the file template.conf in the nginx npm module. It's just a nunjucks template that builds an nginx configuration based on your mechanic settings.

You can copy that template anywhere you like, make your own modifications, then use mechanic set template to tell mechanic where to find it.

Lazy overrides

If you don't want to customize our template, check out the convenience override files that mechanic creates for you:

/etc/nginx/mechanic-overrides/myshortname/top
/etc/nginx/mechanic-overrides/myshortname/server
/etc/nginx/mechanic-overrides/myshortname/location
/etc/nginx/mechanic-overrides/myshortname/proxy

top is loaded before any of mechanic's directives for that site. Use it when nothing else fits.

server is included inside the server block for the site, just before the location block, when redirect-to-https is not in effect. It is a good place to change a setting like access_log.

location is included inside the location block, and is a good place to add something like CORS headers for static font files. It is also a good place to change the client_max_body_size directive.

proxy is loaded inside the proxy server configuration and is ideal if you need to override mechanic's proxy settings.

These files start out empty; you can add whatever you like.

Of course, if this isn't enough flexibility for your needs, you can create a custom template.

Refreshing your nginx configuration

Maybe you updated mechanic with npm update -g mechanic and you want our latest configuration. Maybe you edited your custom template. Either way, you want to rebuild your nginx configuration without changing any settings:

mechanic refresh

Resetting to the defaults

To completely reset mechanic, throwing away everything it knows:

mechanic reset

Warning: like it says, this will completely reset your configuration and forget everything you've done. Don't do that unless you really want to.

Listing your configuration settings

mechanic list

This gives you back commands sufficient to set them up the same way again. Great for copying to another server. Here's some sample output:

mechanic set restart "/usr/sbin/nginx -s reload"
mechanic add test --host=test.com --aliases=www.test.com --canonical=true --https=true
mechanic add test2 --host=test2.com --aliases=www.test2.com,test2-prelaunch.mycompany.com

If you want to wipe the configuration on another server before applying these commands there, use mechanic reset.

Custom nginx templates

You don't have to use our nginx configuration template.

Take a look at the file template.conf in the nginx npm module. It's just a nunjucks template that builds an nginx configuration based on your mechanic settings.

Custom nginx path

If you use brew (a package manager for mac) to install nginx, nginx install path will be /usr/local/etc/nginx. Mechanic default nginx path is /etc/nginx. You can change default nginx path below:

mechanic set restart 'brew services restart nginx'
mechanic set conf '/usr/local/etc/nginx/conf.d'
mechanic set overrides /usr/local/etc/nginx/mechanic-overrides
mechanic set logs /usr/local/var/log/nginx

Storing the database in a different place

It's stored in /var/lib/misc/mechanic.json. That's one hundred percent correct according to the filesystem hierarchy standard, adhered to by all major Linux distributions and many other flavors of Unix. But if you absolutely insist, you can use the --data option to specify another location. You'll have to do it every time you run mechanic, though. That's why we only use this option for unit tests.

If necessary mechanic will create /var/lib/misc.

Credits

mechanic was created to facilitate our work at P'unk Avenue. We use it to host sites powered by ApostropheCMS.

mechanic's People

Contributors

abea avatar boutell avatar breyell avatar dependabot[bot] avatar housemeow avatar indatawetrust avatar jsumnersmith avatar t3rminus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mechanic's Issues

why mechanic install process needs nod.js to be installed before ?

I tried to follow your install prices , but I got a config error .... it's not stated in the doc that node.js is a requirement ... is not it ? thanks for sharing

yves@legolas:~$ sudo npm install -g mechanic
npm http GET https://registry.npmjs.org/mechanic
npm http 304 https://registry.npmjs.org/mechanic
npm http GET https://registry.npmjs.org/boring
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/nunjucks
npm http GET https://registry.npmjs.org/prettiest
npm http GET https://registry.npmjs.org/shell-escape
npm http GET https://registry.npmjs.org/shelljs
npm http 200 https://registry.npmjs.org/lodash
npm http 200 https://registry.npmjs.org/shelljs
npm http GET https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz
npm http GET https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz
npm http 200 https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz
npm http 200 https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz
npm http 200 https://registry.npmjs.org/nunjucks
npm http 200 https://registry.npmjs.org/prettiest
npm http 200 https://registry.npmjs.org/boring
npm http GET https://registry.npmjs.org/nunjucks/-/nunjucks-1.3.4.tgz
npm http GET https://registry.npmjs.org/prettiest/-/prettiest-0.1.0.tgz
npm http GET https://registry.npmjs.org/boring/-/boring-0.1.0.tgz
npm http 200 https://registry.npmjs.org/nunjucks/-/nunjucks-1.3.4.tgz
npm http 200 https://registry.npmjs.org/shell-escape
npm http GET https://registry.npmjs.org/shell-escape/-/shell-escape-0.2.0.tgz
npm http 200 https://registry.npmjs.org/boring/-/boring-0.1.0.tgz
npm http 200 https://registry.npmjs.org/shell-escape/-/shell-escape-0.2.0.tgz
npm http 200 https://registry.npmjs.org/prettiest/-/prettiest-0.1.0.tgz
npm http GET https://registry.npmjs.org/fs-ext
npm http 200 https://registry.npmjs.org/fs-ext
npm http GET https://registry.npmjs.org/fs-ext/-/fs-ext-0.4.6.tgz
npm http 200 https://registry.npmjs.org/fs-ext/-/fs-ext-0.4.6.tgz
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/chokidar
npm http 200 https://registry.npmjs.org/optimist
npm http 200 https://registry.npmjs.org/chokidar
npm http GET https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz
npm http GET https://registry.npmjs.org/chokidar/-/chokidar-0.12.6.tgz
npm http 200 https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz
npm http 200 https://registry.npmjs.org/chokidar/-/chokidar-0.12.6.tgz
npm http GET https://registry.npmjs.org/nan
npm http 200 https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/nan/-/nan-1.9.0.tgz
npm http 200 https://registry.npmjs.org/nan/-/nan-1.9.0.tgz
npm http GET https://registry.npmjs.org/readdirp
npm http GET https://registry.npmjs.org/async-each
npm http GET https://registry.npmjs.org/fsevents
npm http 200 https://registry.npmjs.org/async-each
npm http 200 https://registry.npmjs.org/readdirp
npm http 200 https://registry.npmjs.org/fsevents
npm http GET https://registry.npmjs.org/async-each/-/async-each-0.1.6.tgz
npm http GET https://registry.npmjs.org/readdirp/-/readdirp-1.3.0.tgz
npm http GET https://registry.npmjs.org/fsevents/-/fsevents-0.3.8.tgz
npm http 200 https://registry.npmjs.org/async-each/-/async-each-0.1.6.tgz
npm http 200 https://registry.npmjs.org/readdirp/-/readdirp-1.3.0.tgz
npm http 200 https://registry.npmjs.org/fsevents/-/fsevents-0.3.8.tgz
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/minimist
npm http 200 https://registry.npmjs.org/wordwrap
npm http 200 https://registry.npmjs.org/minimist
npm http GET https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz
npm http GET https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz
npm http 200 https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz
npm http 200 https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz
npm WARN optional dep failed, continuing [email protected]
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/readable-stream
npm http 200 https://registry.npmjs.org/graceful-fs
npm http 200 https://registry.npmjs.org/minimatch
npm http 200 https://registry.npmjs.org/readable-stream
npm http GET https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz
npm http GET https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz
npm http GET https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.33.tgz
npm http 200 https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz
npm http 200 https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz
npm http 200 https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.33.tgz
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/lru-cache
npm http 200 https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/string_decoder
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/core-util-is
npm http GET https://registry.npmjs.org/isarray/0.0.1
npm http 200 https://registry.npmjs.org/lru-cache
npm http 200 https://registry.npmjs.org/string_decoder
npm http 200 https://registry.npmjs.org/core-util-is
npm http 200 https://registry.npmjs.org/inherits
npm http 200 https://registry.npmjs.org/isarray/0.0.1
npm http GET https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz
npm http GET https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz
npm http GET https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz
npm http GET https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz
npm http 200 https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz
npm http GET https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz
npm http GET https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz
npm http 200 https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz
npm http 200 https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz
npm http 200 https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz
npm http 200 https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz
npm http 200 https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz

[email protected] install /usr/local/lib/node_modules/mechanic/node_modules/prettiest/node_modules/fs-ext
node-gyp configure build

/bin/sh: 1: node: not found
gyp: Call to 'node -e "require('nan')"' returned exit status 127. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:431:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.13.0-71-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "configure" "build"
gyp ERR! cwd /usr/local/lib/node_modules/mechanic/node_modules/prettiest/node_modules/fs-ext
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! weird error 1
npm ERR! not ok code 0

Installation Issues

Hi, I'm having some issues with installation
I've read through the other related issues, and yes all the c/c++ compilers are installed

Tested Device 1:

  • Platform: Google Cloud
  • OS: Debian 9.4
  • Node: v8.11.3
  • Node-GYP: v3.8.0
  • NPM: v6.9.0

Tested Device 2:

  • Platform: Proxmox (KVM)
  • OS: Ubuntu 18.04
  • Node: v10.17.0
  • Node-GYP: v5.0.3
  • NPM: v6.11.3

Tested Device 3:

  • Platform: Proxmox (LXC)
  • OS: Debian 9.8
  • Node: v11.15.0
  • Node-GYP: v3.8.0
  • NPM: 6.7.0
root@ld-01:~# npm i -g mechanic
/usr/bin/mechanic -> /usr/lib/node_modules/mechanic/bin/mechanic

> [email protected] install /usr/lib/node_modules/mechanic/node_modules/fs-ext
> node-gyp configure build

gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/8.11.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/mechanic/node_modules/fs-ext/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/mechanic/node_modules/fs-ext/.node-gyp'
gyp ERR! System Linux 4.9.0-6-amd64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/lib/node_modules/mechanic/node_modules/fs-ext
gyp ERR! node -v v8.11.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/mechanic/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-12-30T10_40_14_772Z-debug.log
root@ld-01:~#

Any ideas?

issue installing (node v6.11, centOS 7.3)

not sure what the best node / npm / centos versions are recommended here. but i'm running:

node -v 6.11.0
npm -v 3.10.10
centOS 7.3 x64

> [email protected] install /usr/local/lib/node_modules/mechanic/node_modules/fs-ext
> node-gyp configure build

gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/6.11.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mechanic/node_modules/fs-ext/.node-gyp"
make: Entering directory `/usr/local/lib/node_modules/mechanic/node_modules/fs-ext/build'
  CXX(target) Release/obj.target/fs-ext/fs-ext.o
make: g++: Command not found
make: *** [Release/obj.target/fs-ext/fs-ext.o] Error 127
make: Leaving directory `/usr/local/lib/node_modules/mechanic/node_modules/fs-ext/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/opt/node/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 3.10.0-514.21.1.el7.x86_64
gyp ERR! command "/opt/node/bin/node" "/opt/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/local/lib/node_modules/mechanic/node_modules/fs-ext
gyp ERR! node -v v6.11.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
/usr/local/lib
└── (empty)

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/mechanic/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 3.10.0-514.21.1.el7.x86_64
npm ERR! argv "/opt/node/bin/node" "/usr/local/bin/npm" "install" "-g" "mechanic"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp configure build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the fs-ext package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp configure build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs fs-ext
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls fs-ext
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/npm-debug.log
npm ERR! code 1```

NAN_DEPRECATED errors on new install

Just installed mechanic on Ubuntu 16.04 with node 7.4.0 and nginx 1.10.3 and got a lot of NAN_DEPRECATED errors. Any ideas how to resolve that?

`

/home/bear/.nvm/versions/node/v7.4.0/bin/mechanic -> /home/bear/.nvm/versions/node/v7.4.0/lib/node_modules/mechanic/bin/mechanic

[email protected] install /home/bear/.nvm/versions/node/v7.4.0/lib/node_modules/mechanic/node_modules/fs-ext
node-gyp configure build

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
make: Entering directory '/home/bear/.nvm/versions/node/v7.4.0/lib/node_modules/mechanic/node_modules/fs-ext/build'
CXX(target) Release/obj.target/fs-ext/fs-ext.o
../fs-ext.cc: In function ‘void EIO_After(uv_work_t*)’:
../fs-ext.cc:108:20: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
argv[0] = Nan::NanErrnoException(store_data->error);
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:108:20: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
argv[0] = Nan::NanErrnoException(store_data->error);
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:108:55: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
argv[0] = Nan::NanErrnoException(store_data->error);
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE Flock(Nan::NAN_METHOD_ARGS_TYPE)’:
../fs-ext.cc:297:45: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (i != 0) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:297:45: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (i != 0) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:297:68: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (i != 0) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE Seek(Nan::NAN_METHOD_ARGS_TYPE)’:
../fs-ext.cc:339:56: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (offs_result == -1) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:339:56: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (offs_result == -1) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:339:79: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (offs_result == -1) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE Fcntl(Nan::NAN_METHOD_ARGS_TYPE)’:
../fs-ext.cc:375:51: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (result == -1) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:375:51: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (result == -1) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:375:74: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (result == -1) return Nan::ThrowError(Nan::NanErrnoException(errno));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE UTime(Nan::NAN_METHOD_ARGS_TYPE)’:
../fs-ext.cc:433:47: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char*, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (ret != 0) return Nan::ThrowError(Nan::NanErrnoException(errno, "utime", "", path));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:433:47: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char
, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (ret != 0) return Nan::ThrowError(Nan::NanErrnoException(errno, "utime", "", path));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:433:90: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char
, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (ret != 0) return Nan::ThrowError(Nan::NanErrnoException(errno, "utime", "", path));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE StatVFS(Nan::NAN_METHOD_ARGS_TYPE)’:
../fs-ext.cc:469:47: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char
, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (ret != 0) return Nan::ThrowError(Nan::NanErrnoException(errno, "statvfs", "", path));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:469:47: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char
, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (ret != 0) return Nan::ThrowError(Nan::NanErrnoException(errno, "statvfs", "", path));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
../fs-ext.cc:469:92: warning: ‘v8::Localv8::Value Nan::NanErrnoException(int, const char
, const char*, const char*)’ is deprecated [-Wdeprecated-declarations]
if (ret != 0) return Nan::ThrowError(Nan::NanErrnoException(errno, "statvfs", "", *path));
^
In file included from ../fs-ext.cc:27:0:
../../nan/nan.h:882:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value NanErrnoException(
^
SOLINK_MODULE(target) Release/obj.target/fs-ext.node
COPY Release/fs-ext.node
make: Leaving directory '/home/bear/.nvm/versions/node/v7.4.0/lib/node_modules/mechanic/node_modules/fs-ext/build'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/mechanic/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

`

consider adding php support?

i think mechanic is a great tool but it would be even greater if it also supported proxying other web application types—particularly php. i screwed around with the code a bit as a proof of concept. you can check out my edits here.

Adding an override with a server block causes duplicate warnings to be thrown

In top I have this on the otherplace mechanic overrides directory:

server {
  listen *:80;
  # Redirect old blog traffic to new blog section.
  server_name www.place.com place.com;

  location / {
    rewrite ^(.*)$ http://otherplace.com/first-place$1;
  }
}

Since otherplace has --https=true set, it outputs top above both the 80 and 443 server blocks. This throws the warning:

nginx: [warn] conflicting server name "place.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "place.com" on 0.0.0.0:80, ignored

There should be a way to have the override only printed once or use a port variable in the override (though that'd cause difficulty by requiring a cert on the redirected URL).

Mechanic configuration files

Have no idea why but mechanic didn't update the default site parameter. then I decided to clean /etc/nginx/conf.d/mechanic.conf configuration file, but when I tried to create records again, it sad website already exist.

So, how to reset mechanic completely - I want to try from scratch.

Default HTTPS redirect to 301

This would be for the --redirect-to-https=true flag. Given this is a utility would that be a BC break? I can imagine edge cases.

@austinstarin brought this up in P'unk Slack today. At least this should be an option to pass. No reason I can see why an HTTP to HTTPS redirect should be temporary these days.

Cannot find module 'graceful-fs'

get error when install mechanic
ubuntu 18
node 10

npm install -g mechanic
/root/.nvm/versions/node/v10.15.3/bin/mechanic -> /root/.nvm/versions/node/v10.15.3/lib/node_modules/mechanic/bin/mechanic

> [email protected] install /root/.nvm/versions/node/v10.15.3/lib/node_modules/mechanic/node_modules/fs-ext
> node-gyp configure build

internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module 'graceful-fs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/usr/share/node-gyp/lib/node-gyp.js:12:10)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/mechanic/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-04-24T07_10_59_217Z-debug.log

Add support for nginx from brew on MacOS

Currently the tool struggles to support nginx installed through brew.
If anyone has had success in getting the tool to function in that environment, a guide would be useful in the README.

Problems installing on Nodejs 7.4

Hi,
I cannot get mechanic running on nodejs 7.4. I dont know if that is supported or what?

This is my error code:

node@architectofweb:~$ sudo npm install mechanic -g
/usr/local/nvm/v7.4.0/bin/mechanic -> /usr/local/nvm/v7.4.0/lib/node_modules/mechanic/bin/mechanic

> [email protected] install /usr/local/nvm/v7.4.0/lib/node_modules/mechanic/node_modules/fs-ext
> node-gyp configure build

gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/7.4.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/nvm/v7.4.0/lib/node_modules/mechanic/node_modules/fs-ext/.node-gyp"
gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack     at getNotFoundError (/usr/local/nvm/v7.4.0/lib/node_modules/npm/node_modules/which/which.js:13:12)
gyp ERR! stack     at F (/usr/local/nvm/v7.4.0/lib/node_modules/npm/node_modules/which/which.js:68:19)
gyp ERR! stack     at E (/usr/local/nvm/v7.4.0/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack     at /usr/local/nvm/v7.4.0/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack     at /usr/local/nvm/v7.4.0/lib/node_modules/npm/node_modules/which/node_modules/isexe/index.js:44:5
gyp ERR! stack     at /usr/local/nvm/v7.4.0/lib/node_modules/npm/node_modules/which/node_modules/isexe/access.js:8:5
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:112:15)
gyp ERR! System Linux 3.2.0-4-amd64
gyp ERR! command "/usr/local/nvm/v7.4.0/bin/node" "/usr/local/nvm/v7.4.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/local/nvm/v7.4.0/lib/node_modules/mechanic/node_modules/fs-ext
gyp ERR! node -v v7.4.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
/usr/local/nvm/v7.4.0/lib
âââ (empty)

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/mechanic/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 3.2.0-4-amd64
npm ERR! argv "/usr/local/nvm/v7.4.0/bin/node" "/usr/local/bin/npm" "install" "mechanic" "-g"
npm ERR! node v7.4.0
npm ERR! npm  v4.0.5
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp configure build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the fs-ext package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp configure build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs fs-ext
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls fs-ext
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/node/npm-debug.log

I already tried all the things i can imagine to fix it..

Thanks

Is there any option to remove server headers from response header?

I have a requirement to remove the "server: nginx/version" header from the response header. Usually, people are doing it via nginx config by writing "server_tokens off" and other options. But I am not sure how to do the same with a mechanic. If I write it inside mechanic.conf I am afraid next time any mechanic command will override that.

Problem to add a new site

Hello,
I am trying to add a new site with mechanic, but I always got the same error:
captura de pantalla de 2018-08-07 11-01-56.
I'm using mechanic 1.1.0 and ubuntu 18.04.1
I don't know what to do.
Thanks.

fs-ext compiled against a different Node.js version

Apologies in advance if this is user error.

I'm trying to set up a Meteor environment using this tutorial.

Stuck on the add site step:
mechanic add sitename --host=sitename.com

I just get this error:

Error: The module '/usr/local/lib/node_modules/mechanic/node_modules/fs-ext/build/Release/fs-ext.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 59. Please try re-compiling or re-installing
the module (for instance, using npm rebuild or npm install).
at Object.Module._extensions..node (module.js:689:18)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object. (/usr/local/lib/node_modules/mechanic/node_modules/fs-ext/fs-ext.js:20:15)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)

This appears to be a common node error, but all the recommended solutions (basically uninstall/reinstall or rebuild) I've found don't appear to help.

I've tried npm rebuild on mechanic and fs-ext, uninstalled mechanic, global installed fs-ext, reinstalled mechanic, etc.

What am I missing?

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.