nginx-重写php文件的url

nginx-重写php文件的url,nginx,Nginx,我最近将一个使用Apache的网站迁移到了Nginx 如何获取如下所示的url: http://example.com/login 指向http://example.com/login.php同时不让.php进入url 我当前的配置: server { listen 80; listen [::]:80; root /var/www/example.com/html/; index index.php index.html; server_name

我最近将一个使用Apache的网站迁移到了Nginx

如何获取如下所示的url:

http://example.com/login
指向
http://example.com/login.php
同时不让.php进入url

我当前的配置:

server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com/html/;
    index index.php index.html;

    server_name example.com www.example.com;

    location / {
            try_files $uri $uri/ =404;
    }

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
            deny all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
     location ~ \.php$ {
             include snippets/fastcgi-php.conf;

             # With php7.0-cgi alone:
             # fastcgi_pass 127.0.0.1:9000;
             # With php7.0-fpm:
             fastcgi_pass unix:/run/php/php7.0-fpm.sock;
     }
}

我通常使用这样的东西,它的搜索引擎优化证明。经过我的很多客户网站的测试,效果非常好

在/etc/nginx/conf.d/domain.tld.conf文件中包括以下内容:

server {
  index index.html index.php;
  location / {
    if ($request_uri ~ ^/(.*)\.html$) {  return 302 /$1;  }
    try_files $uri $uri/ $uri.html $uri.php?$args;
  }
  location ~ \.php$ {
    if ($request_uri ~ ^/([^?]*)\.php($|\?)) {  return 302 /$1?$args;  }
    try_files $uri =404;
    # add fastcgi_pass line here, depending if you use socket or port
  }
}

谢谢您的回答。在我当前的配置中。。。它将如何工作?我试过了,但是nginx服务器没有重新启动。