HOW-TO configure PLESK with NGinx (proxy reverse)

Date: 15 March 2010
Source: GraFX

There are a lot of different setup scenarios for this, but we think that we might come with additional information about how to put it together and solve a lot of issues with webmail or domain aliases. First of all I need to thank to Clementin Nedelcu, who wrote an initial hack and to Atomic Corp who are now maintaining the package in their repository and to Parallels, who have come out with some ideas on port change. Also I need to thank to drbalashkewitsh (ID) who has spent some time with us to check our config and gave us some good ideas.

But what is nginx?

nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server written by Igor Sysoev. It has been running for more than five years on many heavily loaded Russian sites including Rambler (RamblerMedia.com). According to Netcraft, nginx served or proxied 4.24% busiest sites in January 2010. Here are some of the success stories: FastMail.FM, Wordpress.com.

What we have additionally to the other resources?

First of all, we have studied the virtual host part. If the basic nginx.conf is the same and works from all packages, we still offer our version of the file, we think we have optimized it a little bit. So where we have some modifications is the virtual host part, working with webmail and domain aliases and mostly that we have a small script in bash scripting, which will generate all the vhost files for all domains, VERY helpful if you have a lot of domains on a server.

Basic setup

First of all if you use ART reporitory, you can simply install with

yum install nginx

If not, then you will need the source files from http://nginx.org/en/download.html (always get the latest)

wget http://sysoev.ru/nginx/nginx-0.x.xx.tar.gz
# Unzip the files with the following command
tar zxvf ./nginx-0.x.xx.tar.gz
# Change directory to the nginx folder
cd nginx-0.x.xx
# Run the following commands:
./configure
# If you get no errors, you're all set, go on with the next couple of commands. If you get an error, try to make sure all the libraries are installed.
make
make install

The folder where to install, we suggest to be /etc/nginx/

Get from our link the nginx.conf and proxy.conf and copy it into your install folder /etc/nginx/. You may edit these files, but should work as it is. The difference between the original one and our solution is the path of the virtual host files. In the ART version, they suggest having it in /etc/nginx/sites/, we have modified the config file and we use it like PLESK style, /var/www/vhosts/*/conf/nginx.conf . Why like this? Because then it is easier to edit from PLESK admin interface in the future.

After this being done, download the following ZIP file from our site - ZIP FILE. Inside of this file you will have generate_nginx_conf.sh file, the bash file and there are several templates files. Copy this to your server, unzip it to a directory (ex. /root/nginx_setup/) and execute the bash file.

sh generate_nginx_conf.sh

You will see where will the new files be added, and if errors popup, you will see them. After this step, you will need to validate the config files.

nginx -t 

If you are returned all OK, then proceed to the next step (on large server may take a while). If you are returned some kind of error, then evaluate the errors and see what you can do. There is an issue, for example if you have a domain moved from your server by the client to an another server, but they did not tell you, you will get back a proxy error, meaning that ngint tries to push a message to port :8080 and of course will get back an error result. Also can be other settings errors, like needing to increase some settings, but all these are easy to handle.

After all is OK and you do not get back errors, you need to execute the following commands

/usr/local/psa/admin/sbin/websrvmng --set-http-port --port=8080
/usr/local/psa/admin/sbin/websrvmng --reconfigure-all
/usr/local/psa/admin/sbin/webmailmng --disable --name=horde
/usr/local/psa/admin/sbin/webmailmng --enable --name=horde
/usr/local/psa/admin/sbin/webmailmng --disable --name=atmail
/usr/local/psa/admin/sbin/webmailmng --enable --name=atmail
/usr/local/psa/admin/sbin/webmailmng --disable --name=atmailcom
/usr/local/psa/admin/sbin/webmailmng --enable --name=atmailcom
service httpd restart
service nginx restart

From now, everything should work, but there is a final step. You will need to open port 8080 in the firewall. This is a COMPULSORY step, we are trying to find out how this can be avoided, but as the proxy tries to connect to http://www.domain.com:8080, this will go through the firewall.

When you create a new domain or subdomain, you will need to create the nginx.conf file in his own VHOST folder, and do not forget this or you will get errors. Also in this case, if you create a domain before the DNS is propagated, you will be returned errors. We try to find out how to avoid these errors, to pass nginx.

We hope that this small tutorial was useful to you and now a lot of your websites will work much faster. We have implemented this tutorial on some of our servers so far and all websites are loading much faster, even up 50% faster.

Other faq items