Installing and Configuring Nginx as an External Web Server: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
==Internal vs External==
==Internal vs External==
The MTA:SA server comes with a built in ('internal') HTTP server which clients use to automatically download resource files. It is only a basic HTTP server which does not support compression or multiple client connections.  
The MTA:SA server comes with a built-in 'internal' HTTP server which clients use to automatically download resource files. It is only a basic HTTP server which does not support compression or multiple client connections.  
By adding an external HTTP server such as Nginx or lighttpd, resource download speed can be increased and bandwidth usage (and player waiting time) decreased.
By adding an external HTTP server such as '''nginx''' or '''lighttpd''', resource download speed can be increased and bandwidth usage (and player waiting time) decreased.
Note that the external HTTP server can be on the same machine as the MTA server.
Note that the external HTTP server can be on the same machine as the MTA server.



Revision as of 22:38, 18 November 2014

Internal vs External

The MTA:SA server comes with a built-in 'internal' HTTP server which clients use to automatically download resource files. It is only a basic HTTP server which does not support compression or multiple client connections. By adding an external HTTP server such as nginx or lighttpd, resource download speed can be increased and bandwidth usage (and player waiting time) decreased. Note that the external HTTP server can be on the same machine as the MTA server.

nginx vs Apache

We recommend nginx or lighttpd as they are better suited to handle the hundreds of file requests that MTA:SA clients will generate. Apache can be used, but will require settings tweaking and the mtasever.conf setting <httpmaxclientrequests> may have to be reduced to prevent timeouts.

The following guide is for installing and configuring nginx solely for MTA:SA. It assumes:

  • You are not already using nginx for other web sites on your server.
  • MTA:SA server is installed on the same server.
  • You are using Debian 7 (but should work on other distributions in a similar way.)

Installing nginx:

Update system:

apt-get update
apt-get upgrade

Install nginx:

apt-get install nginx

Ensure nginx is not running:

/etc/init.d/nginx stop

Configuring nginx:

Edit: /etc/nginx/sites-available/default

Find the 'root' line and change it to point to the http-client-files directory in your MTA:SA server install:

root /PATH_TO_MTA_SERVER/mods/deathmatch/resource-cache/http-client-files;

Find the 'listen' and change it to use an unused server port: (Remove # if present)

listen 20080;

Edit: /etc/nginx/nginx.conf

At the top of the file, add this line to increase the max number of files that can be opened:

worker_rlimit_nofile 5000;

Find the 'worker_connections' line and change it to this:

worker_connections 5000;

Find the 'gzip' settings and make sure gzip is on:

gzip on;

and 'gzip_types' is set for any file type:

gzip_types *;

Testing nginx:

Start nginx:

/etc/init.d/nginx start
Test #1

Open your internet browser, and try this address: http://YOUR_SERVER_IP:20080/admin/client/admin_ACL.lua
If prompted to download a file - SUCCESS!

Test #2

To test the compression is working, go here: http://www.whatsmyip.org/http-compression-test/ and enter http://YOUR_SERVER_IP:20080/admin/client/admin_ACL.lua in the white box and press 'Test'.
If green tick - SUCCESS!

Configure MTA:SA server:

Edit mtaserver.conf

Set httpdownloadurl to be like this:

   <httpdownloadurl>http://YOUR_SERVER_IP:20080</httpdownloadurl>

And start MTA:SA server.

Test it all works!

Connect MTA:SA client and view nginx log files to confirm files are being downloaded: /var/log/nginx/access.log

Final thing

To improve performance, and to avoid huge boring log files, edit /etc/nginx/sites-available/default and add this line under the listen one:

access_log off;

and reload the nginx configuration:

/etc/init.d/nginx reload