1

I use nginx 1.10.1, PHP 5.4.16 (fpm-fcgi).

My files' location is /usr/share/nginx/html/lab/. In this dir, there are multiple .php files, include index.php.

If I put a index.html file in this dir, I can see index.html's content from http://192.168.201.210:8024/lab/ correctly. But If I delete index.html file, I can only get 403 Forbidden.

My php-fam works well, and I saw a lot of solutions not works for me:

Can't open index.php by default with nginx

https://serversforhackers.com/video/php-fpm-configuration-the-listen-directive

This is my nginx's configuration file:

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       8024; # default_server;
        # listen       [::]:8024 ipv6only=on default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {

        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {

        location ~* \.php$ {
            try_files $uri $uri/ = 404;
            include fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
            index index.php index.html;
        }
    }
}
1
  • Do you need an index directive(index index.php) in your catch all location /? Commented Oct 19, 2016 at 6:34

2 Answers 2

0

you can check your log file to get some info tail -n 50 /var/log/nginx/access.log

and do you know about 403,did the php-fpm get right to access web path, like chmod 755 -R /usr/share/nginx/html/lab/

Sign up to request clarification or add additional context in comments.

1 Comment

There is no access.log, I still surprise. Even if I give 777 permission for all files, it still not work. If I access http://192.168.201.210:8024/lab/index.php directly, I can download this file, but I cannot see it in browser.
0

Finally I find the reason: I have another django app listening in the same port - 8024. If I remove the django app's configuration file or modify nginx's configuration file to

listen       8024 default_server;

then, I can access index.php well. But I cannot access my django app at the same port any more.

Here has a very good tutorial for configuring php in nginx: PHP FastCGI Example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.