Nginx has proven to be a very good Web Server capable of serving thousands of requests per second.

Its very popular for developing PHP Enterprise Applications and have it well configured is key in having a high performance PHP Application capable of handling intense workloads and very high traffic websites.

For Nginx to work as very High performance Web Server you need to have configured your Linux kernel as well following this recipe: Linux Kernel Tuning for High Performance LEMP

Step 1. replace the content of the file /etc/nginx/nginx.conf with this:

user nginx;
    error_log  /var/log/nginx/error.log crit;
    pid        /var/run/nginx.pid;
    worker_processes  1;
    worker_rlimit_nofile 16384;
events {
    worker_connections  50000;
    multi_accept on;
    use epoll;
}
http {
    ssl_password_file /etc/nginx/certs/pass_file;
    default_type  application/octet-stream;
    include mime.types;
    access_log  off;
    keepalive_timeout 30;
    fastcgi_read_timeout 3600;
    proxy_read_timeout 3600;
    tcp_nodelay on;
    sendfile on;
    expires -1;
    server_tokens off;
    tcp_nopush on;
    types_hash_max_size 2048;
    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:100m max_size=500m inactive=60m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    gzip  on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_proxied any;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    include /etc/nginx/conf.d/*;
    open_file_cache          max=5000  inactive=20s;
    open_file_cache_valid    30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors   on;
}

 

 worker_processes 1; ### Set this equal to the number of cores or vcores available in the machine

worker_rlimit_nofile 16384; ### This is set with the same number you set in /etc/security/limits.conf

ssl_password_file /etc/nginx/certs/pass_file; ### In this file you will store the password you used for creating SSL Certificates.

 

Step 2. Configure a virtual host with HTTPS following any of the recipes posted in this section.

It is highly recommended that you enable and use HTTPS in HTTP2 with TLS / SSL.

 

Step 3. Restart your Web Server.

$ sudo systemctl restart nginx