My server is running on Ubuntu 16.04. One of my web app(php app) was running on my nginx server. To install ModSecurity I removed the NGINX completely and then followed the following steps to complie and install ModSecurity for NGINX as a Dynamic module:


The problem is my NGINX is running but my web app isn't. When I try to visit my domain I get the following error: "404 Not Found-- nginx/1.15.7". I tried to create a test html project at /var/www/html and tried to browse that project and found HTML code is OK, but if I try to put some PHP file it's not working. Though I checked and found php-fpm is running. Here I'm giving my server block:

server {
modsecurity on;
modsecurity_rules_file /etc/nginx/modsec/main.conf;

root /var/www/html/mysite/public;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name www.mysite.com mysite.com;

    location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html/mysite/public;

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;


Here I should mention that the server block is at /etc/nginx/conf.d/mysite.com.conf and my project is developed on Laravel.

  • 1
    Please have a look into your log files and provide some snippet of relevant entries. Without it is very hard to guess some answer. – Quasimodo's clone Dec 1 '18 at 0:01
  • "but if I try to put some PHP file it's not working." What does actually happen? – Quasimodo's clone Dec 1 '18 at 0:12
  • "I tried to create a test html project at /var/www/html" <> "root /var/www/html/mysite/public;" ? – Quasimodo's clone Dec 1 '18 at 0:19
  • Hi Quasimodo's clone thanks for your suggestion. Actually I fixed it by checking the log file. It says there due to permission issue it was failing to open connection. The user for nginx was 'nginx' but for php-fpm it was 'www-data'. That was the issue. Thanks – Mushfiqur Rahman Dec 1 '18 at 5:12

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.