Auto Start Nginx on Windows

To auto start Nginx on Windows, download

Extract the file, you will find “nssm.exe” file for 32 and 64 bit windows. Copy the file for your Windows version to a folder like


Start a command promt as user Administrator, then to go the folder where nssm.exe is, then run

In the GUI select the nginx.exe path, click install service.

Now in Service Manager, you will see new service Nginx, that is set to autostart by default.

You can right click service name and select start.

See Windows Nginx

Nginx Web Server

Nginx HTTP 414 request-URI too large

On a Nginx server, when accessing a long url, i get error

Nginx HTTP 414 request-URI too large

To fix the error, edit

inside “http” section, find

Replace the line with

If your URL is very large, you may need to increase the 32k to higher or reduce the url length.

Large url like this mostly happend due to bad application design, so if possible try to make URL smaller.

Restart nginx

On older servers (centos 6, ubuntu 14, etc..), run

iredmail increase mail attachment size

Default mail attachment size in iredmail is 10 MB. To increase mail attachment size, login to server as user root, run following commands

Here 104857600 is 100 MB in bytes (100 * 1024 * 1024). Change this as required. Sending very large file using mail attachment is not recommended, it is better use file sharing services like Google Drive, Dropbox, Microsoft OneDrive or another file hosting service for sharing large files.

Now edit php.ini file

Change value for 3 of the following settings. It can be anything above 100 MB or whatever attachment size you want to use.

Restart php-fpm

Edit roundcube configuration file

Set value for

Edit Nginx config file

Set value for

restart nginx


Redirect site from www to non-www

It is better to make web site available with one URL. Many sites work with both wwww and non-www (naked domain) urls.

Using www or non-www is personal choice. One advantage of using wwww for URL is when you have lot of sub domains. If you use non-www url, cookies set by the domain will be available to sub domains. This will increase bandwidth usage as cookie need to be sent with every request browser make to web server.


If you are using Apache web server, you can redirect wwww to non-www url by adding following code in .htaccess file

Redirect non-www to www


If you use Nginx, it is better create a server entry for www URL, then set a redirect

If you want to use same server entry for www and non-www, add following code to nginx server entry for the web site.

Redirect www domain to non-www

If you use custom ports, use

Redirect Naked Domain to www

Related Posts



Nginx Web Server

Show Real IP Nginx Behind Reverse Proxy

When your Nginx web server is running behind a reverse proxy, you will see IP of the reverse proxy server as visitor IP in web servers access log.

To fix this, edit nginx.conf file


Inside http section, add


Restart Nginx

Nginx Web Server

Install Nginx on CentOS 8

To install Nginx web server on CentOS 8, create repo


Install nginx with dnf or yum

Open HTTP and HTTPS ports on firewall

Redirect HTTP to HTTPS when using Reverse Proxy

When you are using Reverse Proxy like Nginx, Haproxy or Amazon ELB in front of web server and web server use HTTP to serve all traffic, you can use normal redirect code based HTTPS variable to do the redirect to HTTPS. You need to use X-Forwarded-Proto to do the redirect.

For Apache, add following code to .htaccess to Apache Virtual Host entry.

For Nginx, add following to server entry for the domain name

For IIS edit web.config, add following to section.

Nginx Location Directive

Nginx Location Directive is used to route request to correct files.


Exact match is used to match an exact URL.

When location is used with no modifiers, then beginning of the URL is matched. In this case, any url http://domain/ok/FILE_NAME will be served from /home/ok/FILE_NAME

Exact Match (=)

Exact match is used to match an exact URL.

In this example http://domain/ok/index.html get served from /home/ok/index.html. Only this specific file will be matched.

Cause Insensitive Regular Expression Match (~*)

Above code routes URL http://domain/ok/ to /home/ok/index.html. But won’t match http://domain/OK/.

If you need both /ok and /OK work, you need to use

With this config, http://domain/OK/FILE will be served from /home/OK/FILE.

See Nginx

nginx password protect

Nginx Password Protect a website

nginx password protect

To password protect a web site, you need to install htpasswd utility. On Ubuntu/Debian, you can install it with command

Now create a password file with command

It will ask for password.

Edit configuration file for your web site and add following in the server entry for the web site.

Restart Nginx.

Now on visiting the web site, you will be asked to enter username and password.

See Nginx

Nginx vs Apache

I recently added nginx as front end for apache. Now nginx serve static content, PHP requests are peroxided to Apache.

Nginx frontend, Apache backend

Apache Only

See Apache, Nginx