Though nginx is now the default web server software, you may still be using (or may have switched to) Apache. Nginx can be used to configure and run pages and software accessible via HTTP and HTTPS. You'll likely find nginx easier to configure, faster and more lightweight than Apache.
You'll need to execute some commands via SSH to get the full use out of this software, though it can be set up via FTP. There is a separate guide on how to connect to your slot via SSH. Commands are kept as simple as possible and in most cases will simply need to be copied and pasted into the terminal window (then executed by pressing the Enter key).
Table of contents
Install nginx by logging in via SSH, then copying and pasting the following:
You can also create this directory using your (S)FTP software of choice. Either way, every 5 minutes the system will scan slots and if it sees an empty .nginx directory it will stop Apache and install nginx for you. That's it!
In addition to the basic installation, the following will also automatically happen (or be attempted):
- PHP will be configured
- Domains served from ~/www
- ruTorrent will be password protected using a .conf> file
- An SCGI mount point will be created for rTorrent at /username/RPC
- Access to areas of ruTorrent which don't need web access will be denied
- Access to all files beginning with .ht will be denied
- Access to any directory with a .htaccess file will be denied
Configuring before starting nginx
As above, the auto-configuration will seek to block access to anything reliant on .htaccess files. Nginx relies on its own configuration files instead - you should look to either convert .htaccess to an nginx config file or, if the software page has a section for nginx users reconfigure according to those instructions. You can review by comparison, using the documentation for the various Apache and nginx documentation.
Once you've reviewed and amended the previous Apache configurations for nginx you can remove its deny-htaccess.conf file from ~/.nginx/conf.d/000-default-server.d
Starting, stopping and restarting
As nginx is started by the system, you'll only be able to kill it: the system will start it up for you automatically every five minutes.
To kill nginx simply run this command via SSH:
pkill -fu "$(whoami)" 'nginx'
You can then check if any part of nginx is still running with ps x | grep nginx | grep -v grep.
Nginx is used via config files which tell the web server what you want to do. This page won't go into much detail on that - software in our software section will contain the specific information you need to configure for nginx.
After you've made your changes you'll need to reload nginx. This is not the same as restarting it (though restarting it would of course reload the configs too). You can reload by running this command:
/usr/sbin/nginx -s reload -c ~/.nginx/nginx.conf
At this point you'll receive an alert. This is normal and is not an error as such:
[server ~] /usr/sbin/nginx -s reload -c ~/.nginx/nginx.conf nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2017/06/03 07:49:30 [notice] 7309#0: signal process started
Errors generally stop nginx from coming back to life post-reload, so you can always run the check command from above to confirm if nginx is running.
If you experience issues or crashes using nginx the first thing to try and do is restart the software using the command listed in the section above, "Starting, stopping and restarting"
- Nginx will not start
This can happen if nginx is reloaded or restarted via any means and is normally related to a config change you've made that is invalid. Even if you made the changes a long time ago, since nginx will only try to load them on reload/restart it might be a while before the error comes to light. You can often see the problematic change by running the reload command:
[server ~/.nginx/conf.d/000-default-server.d] /usr/sbin/nginx -s reload -c ~/.nginx/nginx.conf nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2017/06/03 07:50:11 [emerg] 15787#0: invalid port in upstream "10.0.0.1:/" in /media/sda1/user/.nginx/conf.d/000-default-server.d/sonarr.conf:8
In the above example, there isn't a port in the Sonarr config, so naturally an invalid port issue arises. In this case, adding the correct port Sonarr is listening is what's required. Alternatively, if no longer required, you can delete the config. Either way, you'll need to run the reload command again.
pkill -9 -fu "$(whoami)" 'nginx' rm -rf ~/.nginx