Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
nginx serving only / but not any other files

I have two docker containers as below:

nginx ==> working as proxy web server (nginx web server)
dist  ==> working as a php-fpm container

And this is my dist.conf:

server {
    server_name dist.me.com;
    root /var/www/html;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass dist:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/dist_error.log;
    access_log /var/log/nginx/dist_access.log;
}

The issue is if I enter dist.me.com, it shows my index.php contents fine. But if I enter dist.me.com/index.php or dist.me.com/index2.php, I get error 404 Not Found.

I tried changing some values of conf file but it did not help me.

Both index.php and index2.php exist in /var/www/html path.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your existing dist.conf is designed to block URIs ending with .php. The internal directive prevents a location from being directly accessed, and there is also a location which explicitly returns 404 for any URI ending with .php.

You need to change the location rule, remove the internal directive, and delete the location block which follows it.

For example, replace location ~ ^/index\.php(/|$) { ... } and location ~ \.php$ { ... } with the single location block as follows:

location ~ \.php(/|$) {
    fastcgi_pass dist:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!