search

Home  >  Q&A  >  body text

What is the function of nginx’s index directive?

server {
        listen 80;
        server_name phpcms.me m.phpcms.me;
        root /mnt/hgfs/www/open/phpcms;
        charset utf-8;
        index index.html index.php;
        try_files $uri $uri/ @rewrite;
        location ~ \.php {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include /etc/nginx/fastcgi.conf;
        }
        location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/;
        }
}

This is my nginx configuration. There is a qiantu directory in the root directory of the website, which contains static content pages and the file index.html does not exist.
You can access the homepage of the list page through phpcms.me/qiantu/index.html, and the @rewrite rule is followed
But through phpcms.me/qiantu/, it is directly 403 forbidden, and the @rewrite rule is not followed at all.
But delete the qiantu directory in the root directory and access phpcms.me/qiantu/, and you can access it through the @rewrite rule.
I would like to ask how to retain the qiantu directory in the root directory while accessing phpcms.me/qiantu/ so that it can be matched by location instead of directly 403 forbidden

The qiantu directory here is just an example and is not fixed, so it cannot be matched by location = /qiantu/ {}.

PHP中文网PHP中文网2757 days ago441

reply all(1)I'll reply

  • 为情所困

    为情所困2017-05-16 17:22:27

    Try it under chmod

    reply
    0
  • Cancelreply