NTUT-112-project / api-server

0 stars 0 forks source link

nginx reverse proxy "403 Forbidden error" #3

Open James-Lu-none opened 2 months ago

James-Lu-none commented 2 months ago

nginx reverse proxy getting "403 Forbidden error" for a line added to default.conf as follow:

# basic config for a PHP application served by Nginx and PHP-FPM (FastCGI Process Manager).
server {
    listen 80;
    server_name localhost;

    # the default response file when client requests to a directory rather than a file (e.g. /about/ instead of /about.html)
    index index.php index.html index.htm;

    # directory for logs
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    # root directory for the application (./src/public/index.php)
    root /var/www/public;

    # how to respond to requests for the root URL (/).
    location / {
        index index.html index.htm;
        # this line ^^^^^^^^^^^^ causing 403 Forbidden error
        try_files $uri $uri/ /index.php?$query_string;
    }

    # how to respond to requests for PHP files.
    location ~ \.php$ {
        # fastcgi_* directives are used to pass the request to a FastCGI server (server on app:9000)
      try_files $uri = 404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass app:9000;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

log

2024-09-12 14:53:11 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
2024-09-12 14:53:11 /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
2024-09-12 14:53:11 /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
2024-09-12 14:53:11 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
2024-09-12 14:53:11 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
2024-09-12 14:53:11 /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
2024-09-12 14:53:11 /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
2024-09-12 14:53:11 /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
2024-09-12 14:53:11 /docker-entrypoint.sh: Configuration complete; ready for start up
2024-09-12 14:56:12 172.18.0.1 - - [12/Sep/2024:06:56:12 +0000] "GET / HTTP/1.1" 403 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: using the "epoll" event method
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: nginx/1.27.1
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: built by gcc 13.2.1 20240309 (Alpine 13.2.1_git20240309) 
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: OS: Linux 6.10.0-linuxkit
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker processes
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 29
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 30
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 31
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 32
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 33
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 34
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 35
2024-09-12 14:53:11 2024/09/12 06:53:11 [notice] 1#1: start worker process 36
2024-09-12 14:56:12 2024/09/12 06:56:12 [error] 35#35: *1 directory index of "/var/www/public/" is forbidden, client: 172.18.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:8080"
James-Lu-none commented 2 months ago

issue solved after the line index index.html index.htm; was removed