All HowTo's Cyber-Security Linux Redhat, Fedora and CentOS Linux Web Servers

Sample NginX & php-fpm configuration with SSL on CentOS 7 and RHEL 7

This article shows an example configuration for NginX with php-fpm on CentOS 7. This is not a HowTo but rather something for you to copy/paste to help you on your way.

The website domain is “www.example.com” and we’re serving SSL as well. You can ignore that part if you like. Our site configuration files are in “/etc/nginx/conf.d/”. Our SSL certificates and related files are in “/etc/nginx/ssl/”. Our website content will be served from “/var/www/www.example.com”.

The HTTP configuration file: “/etc/nginx/conf.d/www.example.com.conf”

server {
        listen 80;
        server_name www.example.com;

        access_log   /var/log/nginx/www.example.com.access.log;
        error_log    /var/log/nginx/www.example.com.error.log;

        root /var/www/www.example.com;
        index index.php;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ .php$ {
                #try_files $uri =404;
                include fastcgi_params;
                include fastcgi.conf;
                fastcgi_index  index.php;
                fastcgi_pass   127.0.0.1:9000;
        }
}

The HTTPS configuration file: “/etc/nginx/conf.d/ssl-www.example.com.conf”

server {

        ssl    on;
        ssl_certificate    /etc/nginx/ssl/bundle.crt;
        ssl_certificate_key    /etc/nginx/ssl/www.example.com-priv.key;

        listen 443;
        server_name www.example.com;

        access_log   /var/log/nginx/ssl-www.example.com.access.log;
        error_log    /var/log/nginx/ssl-www.example.com.error.log;

        root /var/www/www.example.com;
        index index.php;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ .php$ {
                #try_files $uri =404;
                include fastcgi_params;
                include fastcgi.conf;
                fastcgi_index  index.php;
                fastcgi_pass   127.0.0.1:9000;
        }
}

Leave a Reply

Your email address will not be published. Required fields are marked *