Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:45:23+00:00 2026-05-31T11:45:23+00:00

I almost have it working, but even then not sure if it’s properly implemented.

  • 0

I almost have it working, but even then not sure if it’s properly implemented. (I’m new to Nginx!)

My test has this directory structure:

/index.php (root directory front controller)
/test/index.php (sub directory front controller)
/include/include.php (some PHP include)

Files named index.php are the front controllers.

The Nginx server block:

server {
    listen 80;
    server_name mysite.com;

    root /var/www/mysite.com/http;
    index index.php;

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

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

    location @rewrite {
        rewrite ^ /index.php last;
    }
}

These cases currently work and need to work like this:

1. http://mysite.com/ => /index.php (exists)
2. http://mysite.com/test => /test/index.php (exists)
3. http://mysite.com/test/index.php => /test/index.php (exists)
4. http://mysite.com/test/foobar => /index.php (/test/foobar didn't exist)
5. http://mysite.com/asdf => /index.php (/asdf didn't exist)
6. http://mysite.com/asdf.php => /index.php (/asdf.php didn't exist)
7. http://mysite.com/asdf/index.php => /index.php (didn't exist; the try_files @rewrite fixes this, otherwise I get "No input file specified.")

The case I don’t have yet is:

8. http://mysite.com/include/include.php => /index.php

Currently accessing a PHP file that exists that isn’t a front controller is processing that script. I can understand why it’s doing it, it’s try(ing)_files $uri @rewrite and finding include.php. I’ve been trying to fix it with rewrites, but no dice. Or is there a better way, with location blocks/try_files?

In general am I going about this server block correctly for my intentions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:45:24+00:00Added an answer on May 31, 2026 at 11:45 am

    How about …

    server {
        listen 80;
        server_name mysite.com;
    
        root /var/www/mysite.com/http;
        index index.php;
    
        location / {
            try_files $uri $uri/ /index.php;
        }
    
        location ~ \.php$ {
            location ~ /index\.php$ {
                if (!-e $request_filename) {
                        rewrite ^ /index.php break;
                }
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
            }
            rewrite ^ /index.php last;
        }
    }
    

    This will serve …

    yoursite/any_path/ => yoursite/any_path/index.php
    yoursite/any_path/index_file.php => yoursite/any_path/index.php
    yoursite/any_path/any_non_index_file.php => yoursite/index.php 
    

    … which is what your question suggests you want (last one seems strange to me)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new in C# but not new to coding --being doing it for almost
I have big enough and already working project, written not by a programmer, but
I have an almost new setup of ROR 3.1 here and have already generated
I have tried almost all the solutions from SO but no success :(. I
I am new to cakephp and have been working through the Apress book Beginning
I have been working with .Net since VS2002 and since then any time that
I have trying hard, but can't make this method works properly. The usage format
First of all: I am not an experienced ClearCase user, but I have lots
Sorry for the non-descript title, but I'm not sure how to phrase it. Currently,
The application I'm working on is almost finished but we've come to a crossroads.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.