Nginx:设置默认文件扩展名 [英] Nginx: Setting a default file extension

查看:82
本文介绍了Nginx:设置默认文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将对nginx使用什么规则,所以我的默认文件扩展名为.php?

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

我目前使用www.mywebsite.com/ home.php 访问页面,但我只想使用www.mywebsite.com/home

I currently access a pages using www.mywebsite.com/home.php but I want to just use www.mywebsite.com/home

谢谢

推荐答案

假设您还希望提供静态文件,则可以使用以下方式:

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

这篇关于Nginx:设置默认文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆