开发者

Nginx: Setting a default file extension

开发者 https://www.devze.com 2023-04-13 01:51 出处:网络
What rule would I use for nginx so my default file extension is .php? I currently access a pages usingwww.mywebsite.com/home.php but I want to just use www.mywebsite.com/开发者_JS百科home

What rule would I use for nginx so my default file extension is .php?

I currently access a pages using www.mywebsite.com/home.php but I want to just use www.mywebsite.com/开发者_JS百科home

Thanks


Assuming you also want to serve static files, you could use something like this:

server {
  server_name example.com;

  # Set the docroot directly in the server
  root /var/www;

  # Allow index.php or index.html as directory index files
  index index.html index.php;

  # See if a file or directory was requested first.  If not, try the request as a php file.
  location / {
    try_files $uri $uri/ $uri.php?$args;
  }

  location ~ \.php$ {
    # If the php file doesn't exist, don't pass the request to php, just return a 404
    try_files $uri =404;

    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $request_filename;

    fastcgi_pass your_php_backend_address;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号