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

jlrdw's avatar
Level 75

Nginx point to public

I use Apache, but want to try nginx.

To avoid having to do a VH every time I install a new WAMP, I have this htaccess in root to point to public as document root:


    RewriteEngine On
    RewriteRule ^(.*)$ public/
    RewriteRule ^ server.php

Of course in public the "out of box" htaccess is there:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    RewriteBase /laravel842/    // only modified line

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    # RewriteRule ^(.*)$ public/ [L]
</IfModule>

What is the equivalent in nginx to "direct" to public as document root?

0 likes
10 replies
neilstee's avatar

@jlrdw if you want to point your server to the public directory of your laravel project, you can just set the root directory like this inside the server

server {
	root /var/www/your-laravel-project/public;
	// your other configurations...
}
jlrdw's avatar
Level 75

@tray2 is that guide only for Linux only? I use WIndows 10.

@sinnbeck and @tray2 nginx doesn't have a folder level (document root) .htaccess equivalent?

Of course I'm going to search more, but I have never had to do in depth learning to use apache, one setting in the conf file and it just works.

Just changing

     AllowOverride None

    to

    AllowOverride FileInfo

And that's it, the rest you can accomplish through the .htaccess files/s.

Also @sinnbeck notice above I use two .htaccess files, small one only sets public as document root.

In nginx is a VH the only way to do the same?

Tray2's avatar
Tray2
Best Answer
Level 73

Yes it's Linux only but the part about the virtual host setting are still valid. You need to change some paths other than that you should be good.

Couldn't find a good one for windows though.

1 like
jlrdw's avatar
Level 75

Okay I'll close this one, will probably stick to Apache. Wish Jeffrey allowed more than one best answer.

@tray2 in the article it mentions

Now activate the virtual host by creating a symlink of the 'laravel' file to the 'sites-enabled' directory.

I do not like symlink's because if I develop in Windows, but site is linux it is different.

I even use a script to serve images.

1 like
Tray2's avatar

Linux loves symlinks and they are good in *nix systems but on windows it better to copy the file to where it's supposed to be.

jlrdw's avatar
Level 75

Thanks @neilstee @sinnbeck @sinnbeck for your replies.

I played around a little with it and noticed you could do a virtual host or just point to public in the conf file. So that is similar to htaccess except you don't do it in the project, it's in conf.

I was hoping you could do that at project level, like .htaccess. but now at least I have a feel for how nginx works.

Sinnbeck's avatar

Yeah nginx is quite focuses on doing everything from its own conf file. But personally I like that, as I have have it set up once correctly in docker for everyone :)

Please or to participate in this conversation.