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 another question

I currently have a couple of site working fine in nginx. The working 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  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;
        }
    }

    


}


However I wanted to experiment with setting up laravel in a sub folder like @fideloper shows on the serversforhackers site, his code:

server {
    listen 80 default_server;

    root /var/www/top/public;

    index index.html index.htm index.php;

    server_name _;

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

    location /nested {
        alias /var/www/nested/public;
        try_files $uri $uri/ @nested;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
    }

    location @nested {
        rewrite /nested/(.*)$ /nested/index.php?/ last;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

fastcgi adapted for nginx for Windows. But all I get is:

No input file specified. 

Normally I have main laravel out of web, and that setup works, I just can't figure out laravel in subfolder.

Any pointers?

0 likes
2 replies
jlrdw's avatar
Level 75

I tried this:

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;

            root /nginx/www/laravel842/public;
            location / {
                index index.html index.htm index.php;
            try_files $uri $uri/ /index.php?$query_string;
            }

        location ~ \.php$ {
        try_files $uri /index.php = 404;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }



       
   
    }
   
}

That worked, but the problem is the url is like:

http://localhost/

and

http://localhost/login/

I wanted:

http://localhost/laravel842/login

I also tried:

worker_processes  1;

events {
    worker_connections  1024;
}


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

    sendfile        on;
    keepalive_timeout  65;

    server {
            listen 81;   #tried various ports 80 also.
            server_name laravel.test;
            # server_name localhost;     # This line works.
            
            root /nginx/www/laravel842/public;
            location / {
                index index.html index.htm index.php;
            try_files $uri $uri/ /index.php?$query_string;
            }

        location ~ \.php$ {
        try_files $uri /index.php = 404;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }



       
   
    }
   
}

But nginx doesn't seem to work with another server name, I only got:

Hmm. We’re having trouble finding that site.

We can’t connect to the server at www.laravel.test.

If that address is correct, here are three other things you can try:

    Try again later.
    Check your network connection.
    If you are connected but behind a firewall, check that Firefox has permission to access the Web.

Any idea why laravel.test for the server name will not work? Thanks, I am new to nginx. I did add in the host file:

	
127.0.0.1       laravel842.test
    

Please or to participate in this conversation.