Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jlrdw's avatar
Level 75

[SOLVED] Nginx Windows10 and PHP 8

I am new to Nginx, have used Apache.

I have a question on setting up sites: My nginx.conf is:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /mini4/index.php?$args;

        }

  
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            include "fastcgi.conf";
            
            root           www;
            #try_files $uri $uri/ /404.php?$args;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    


}


This works fine with a site as shown above mini4. Or http://localhost/mini4

But I want to add more sites. Can I just add more server blocks in nginx.conf, or do I need separate conf files? And this is my first day of using nginx. Note development only.

0 likes
5 replies
jlrdw's avatar
Level 75

I changed nginx.conf to:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$args;

        }

  
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            include "fastcgi.conf";
            
            root           www;
            #try_files $uri $uri/ /404.php?$args;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    
    include "mini4.conf";

}


And included mini4.conf:

    server {
        listen       80;
        server_name  mini4;

        location / {
            root   www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /mini4/index.php?$args;

        }

  
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            include "fastcgi.conf";
            
            root           www;
            #try_files $uri $uri/ /404.php?$args;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

But still only the nginx.conf seems to be working, it's not recognizing the include.

So that is where I am having trouble, setting up more server blocks.

apex1's avatar

Silly question, but did you restart nginx?

1 like
jlrdw's avatar
Level 75

Yes restarted, seems I can only get one server block working at a time, any includes are not working.

I even setup multiple in same file:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  mini4;
        # server_name  localhost

        location /mini4/ {
            root   www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /mini4/index.php?$args;

        }

  
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            include "fastcgi.conf";
            
            root           www;
            #try_files $uri $uri/ /404.php?$args;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    server {
        listen       80;
        server_name  tjhs;
        # server_name  localhost

        location /tjhs/ {
            root   www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /tjhs/index.php?$args;

        }

  
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            include "fastcgi.conf";
            
            root           www;
            #try_files $uri $uri/ /404.php?$args;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    


}

But only top server block is recognized.

It's as though the bottom server block isn't even there. But the top server block works perfect.

jlrdw's avatar
Level 75

@apex1 @siangboon I got it, found a Digital Ocean article: I just needed two location blocks, not two server blocks. If it helps anyone, here is final conf file:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        # server_name  tjhs;
        server_name  localhost;

        location /mini4/ {
            root   www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /mini4/index.php?$args;

        }


        location /tjhs/ {
            root   www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /tjhs/index.php?$args;

        }

  
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            include "fastcgi.conf";
            
            root           www;
            #try_files $uri $uri/ /404.php?$args;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    


}


Seems there isn't one place that covers all this for nginx.

1 like

Please or to participate in this conversation.