Installing and Configuring Nginx as an External Web Server: Difference between revisions
(Created page with " ==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, bu...") |
(Fix typo) |
||
(11 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
==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== | ==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 | 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 mtaserver.conf setting <'''httpmaxconnectionsperclient'''> may have to be reduced to prevent timeouts. | ||
The following guide is for installing and configuring nginx solely for MTA:SA. It assumes: | The following guide is for installing and configuring nginx solely for MTA:SA. It assumes: | ||
Line 20: | Line 24: | ||
==Configuring nginx:== | ==Configuring nginx:== | ||
<!-- | |||
====Edit: /etc/nginx/sites-available/default==== | ====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: | 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; | root /PATH_TO_MTA_SERVER/mods/deathmatch/resource-cache/http-client-files; | ||
Find the ''''listen'''' and change | Find the ''''listen'''' and change it to use an unused server port: (Remove # if present) | ||
listen 20080; | listen 20080; | ||
--> | |||
====Edit: /etc/nginx/sites-enabled/mta-server1==== | |||
In the directory '''/etc/nginx/sites-enabled/''' create a file called '''mta-server1''' with the following content: | |||
server { | |||
listen 20080; | |||
root /PATH_TO_MTA_SERVER/mods/deathmatch/resource-cache/http-client-files; | |||
server_name localhost; | |||
access_log off; | |||
autoindex off; | |||
} | |||
'''**Important**: Change PATH_TO_MTA_SERVER to the actual absolute path of your MTA:SA server install directory''' | |||
====Edit: /etc/nginx/nginx.conf==== | ====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: | At the top of the file, add this line to increase the max number of files that can be opened: | ||
Line 40: | Line 55: | ||
/etc/init.d/nginx start | /etc/init.d/nginx start | ||
====Test #1==== | =====Test #1===== | ||
Open your internet browser, and try this address: '''<nowiki>http://YOUR_SERVER_IP:20080/admin/client/admin_ACL.lua</nowiki>'''<br/> | Open your internet browser, and try this address: '''<nowiki>http://YOUR_SERVER_IP:20080/admin/client/admin_ACL.lua</nowiki>'''<br/> | ||
If prompted to download a file - SUCCESS! | If prompted to download a file - SUCCESS! | ||
'''Note''': If you are getting a 403 Forbidden response, nginx cannot access the files. Usually this means the user (www-data) is lacking ''execute'' permission on the server, mods, deathmatch, resource-cache, http-client-files folders. | |||
=====Test #2===== | =====Test #2===== | ||
Line 51: | Line 68: | ||
====Edit mtaserver.conf==== | ====Edit mtaserver.conf==== | ||
Set '''httpdownloadurl''' to be like this: | Set '''httpdownloadurl''' to be like this: | ||
<httpdownloadurl>http://YOUR_SERVER_IP:20080</httpdownloadurl> | <httpdownloadurl>'''<nowiki>http://YOUR_SERVER_IP:20080</nowiki>'''</httpdownloadurl> | ||
And start MTA:SA server. | And start MTA:SA server. | ||
<!-- | |||
==Test it all works!== | ==Test it all works!== | ||
Connect MTA:SA client and view nginx log files to confirm files are being downloaded: '''/var/log/nginx/access.log''' | Connect MTA:SA client and view nginx log files to confirm files are being downloaded: '''/var/log/nginx/access.log''' | ||
Line 63: | Line 81: | ||
and reload the nginx configuration: | and reload the nginx configuration: | ||
/etc/init.d/nginx reload | /etc/init.d/nginx reload | ||
--> |
Latest revision as of 12:30, 13 January 2024
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 mtaserver.conf setting <httpmaxconnectionsperclient> 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-enabled/mta-server1
In the directory /etc/nginx/sites-enabled/ create a file called mta-server1 with the following content:
server { listen 20080; root /PATH_TO_MTA_SERVER/mods/deathmatch/resource-cache/http-client-files; server_name localhost; access_log off; autoindex off; }
**Important**: Change PATH_TO_MTA_SERVER to the actual absolute path of your MTA:SA server install directory
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!
Note: If you are getting a 403 Forbidden response, nginx cannot access the files. Usually this means the user (www-data) is lacking execute permission on the server, mods, deathmatch, resource-cache, http-client-files folders.
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.