fnpd

i felt angry that nginx is too complex while most sites use it. docker doesn't help.

user story

i can access following urls by browsers AND curl:

  1. http://127.0.0.1
  2. http://127.0.0.1/index.php
  3. http://127.0.0.1/version.php
  4. http://127.0.0.1/blog
  5. http://127.0.0.1/blog/index.php

first

i firstly tried:

version: '3'
# https://marc.it/dockerize-application-with-nginx-and-php8/
services:
  web:
    image: nginx:latest
    ports:
      - '80:80'
    volumes:
      - ./src:/var/www/html
      - ./nginx:/etc/nginx/conf.d
    links:
      - php-fpm
  php-fpm:
    image: php:8-fpm
    volumes:
      - ./src:/var/www/html
; ./nginx/default.conf
server {
    index index.php index.html;
    server_name phpfpm.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

but while we can only access 1, 2, and 3, that means http://127.0.0.1/blog and http://127.0.0.1/blog/index.php will failed when access by browsers.

lets try different one by chatgpt

second

chatgpt doesn't help either

version: '3'
services:
  web:
    image: nginx:latest
    volumes:
      - ./nginx:/etc/nginx
      - ./src:/var/www/html
    ports:
      - 80:80
  php:
    image: php:fpm
    volumes:
      - ./src:/var/www/html
; ./nginx/nginx.conf
worker_processes 1;

events { worker_connections 1024; }

http {
    server {
        listen 80;
        index index.php index.html;
        server_name localhost;
        error_log  /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
        root /var/www/html;

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass php:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        location /blog {
            try_files $uri $uri/ /a/index.php?$query_string;
        }
    }
}

it cannot access at all and waste three hours

just give up

why nginx make everone suffer?