简体   繁体   中英

Nginx not showing index.php

So guys i have runned a docker-compose who contain instructions to up a container with nginx another with php and another with mysql, but when i try to acess nginx he gives me this error:

403 Forbidden

I think that could be something wrong in his config, here his config file:

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 /code;

    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;
    }
}

For the case here is the docker-compose file:

version: '2'
services:
    web:
        image: nginx:latest
        ports:
            - "80:80"
        volumes:
            - ./code/public_html:/code
            - ./site.conf:/etc/nginx/conf.d/default.conf
        links:
            - php
    php:
        image: php7-custom-conf
        volumes:
            - ./code/public_html:/code
        links:
            - db
    db:
        image: mysql:5.7
        volumes:
        - "./.data/db:/var/lib/mysql"
        restart: always
        ports:
            - "3306:3306"
        environment:
         MYSQL_ROOT_PASSWORD: dbrootpass
         MYSQL_DATABASE: dbname
         MYSQL_USER: dbuser
         MYSQL_PASSWORD: dbpass

Any help is appreciated, anyway thanks for the attention. Sorry for any errors not a english speaker here ;)

The problem is in your location ~ \\.php$ .

Try replacing it with:

location ~ \.php$ {
    proxy_pass http://php:9000;
}

I retest it. If you connect to http://localhost/ it'll return a 403 because the rights are wrong (thanks to @dizeee) but if you try to connect to http://localhost/index.php it returns a 404 because the proxy_pass is not defined.

Your configuration is fine. But it looks like nginx can't access your code/public_html folder. Make sure it's executable for all users, eg chmod 0755 ./code/public_html . Another solution is to change the user and/or group of the nginx process to match the owner of the public_html folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM