Configuring nginx for both static pages and fcgi simultaneously

Maxim Dounin mdounin at
Sun Jul 31 23:15:29 UTC 2016


On Sun, Jul 31, 2016 at 06:55:54PM -0400, Denis Papathanasiou wrote:

> I have the following configuration file defined in
> /etc/nginx/conf.d/my-project.conf (this is on debian).
> It does what I want, in that it serves static contet in the /css, /images,
> /js folders along with index.html correctly.
> And for dynamic requests (I'm running an fcgi-enabled server on port 9001)
> to /contact, /login, and /singup it also works correctly.
> I would just like to be able to declare that anything *except* index.html,
> /css, /images, and /js, it should all go to the fcgi server.
> I've experimented with various definitions of "location", but the only
> one that seems to work is the one I have below, where all the possible
> fcgi paths are defined explicitly.
> Is there a better, simpler way of doing this?

So, you need to pass to fastcgi anything except /, /index.html, 
and anything starting with /css/, /images/, and /js/, right?

Most simple solution would be exactly this, by defining a catch-all 
"location /" to pass anything to fastcgi, and explicitly excluding 
required paths using additional locations:

   root   /var/www/my-project/html;
   index  index.html;

   location / {
       fastcgi_pass ...
       include fastcgi_params;

   location = / {}
   location = /index.html {}
   location /css/ {}
   location /images/ {}
   location /js/ {}

Maxim Dounin

More information about the nginx mailing list