Nginx 从站点url隐藏.html文件扩展名

Nginx 从站点url隐藏.html文件扩展名,nginx,file-extension,Nginx,File Extension,我试过这个,但对我来说不太管用。我得到的不是404错误就是505错误 我正在使用nginx服务器上的Digital Ocean hosting。如果有人想知道我是如何解决这个问题的: 我访问了/etc/nginx/conf.d目录,在那里创建了一个名为“domain.trade.conf”的文件夹,例如,如果我的域是example.com,那么文件夹名就是example.com.conf 在此文件中,我添加了以下代码: server { listen 80; serv

我试过这个,但对我来说不太管用。我得到的不是404错误就是505错误


我正在使用nginx服务器上的Digital Ocean hosting。

如果有人想知道我是如何解决这个问题的:

我访问了/etc/nginx/conf.d目录,在那里创建了一个名为“domain.trade.conf”的文件夹,例如,如果我的域是example.com,那么文件夹名就是example.com.conf

在此文件中,我添加了以下代码:

server {
    listen       80;
    server_name  example.com; #Domain
    root         /var/www/html; #The place of your site files
    access_log   /var/www/html/logs/access.log; #Where to log the accesses
    error_log    /var/www/html/logs/error.log; #Where to log the errors

    location / { 
        try_files $uri $uri/ @htmlext;
    }   

    location ~ \.html$ {
        try_files $uri =404;
    }   

    location @htmlext {
        rewrite ^(.*)$ $1.html last;
    } 
}
希望我能帮助你