Nginx站点可用配置

  • 本文关键字:配置 站点 Nginx nginx
  • 更新时间 :
  • 英文 :


所以,我从Apache移民到Nginx,这对我来说是一次可怕的经历。

现在我需要你的帮助来理解Nginx文件的配置:

server { 
....
location / {
try_files $uri $uri/ $uri.html $uri.php$is_args$args;
}
location ~ "^/([-0-9a-zA-Z_s]+)$" {
try_files $uri $uri/ /user/user?username=$1;
}
location ~ "^/trends/([.*]+)$" {
try_files $uri $uri/ /trends/trend?name=$1;
}

}

当我键入URL栏网站时https://example.com/someuser,它成功地将我重定向到文件夹example.com/user/user?username=someuser。但当我试图访问https://example.com/trends/sometrendNginx从第一块加载页面给我。为什么要这样做?谢谢你的帮助。

很抱歉,我回复得很晚,但我想这对其他人会有帮助,他们将面临类似的问题:

server {
...
# enable utf8
charset UTF-8;
# pretty urls
# user folder
location ~ "^/([-0-9a-zA-Z_s]+)$" {
try_files $uri $uri/ /user/user?username=$1;
}
# trends
location ~ "^/trends/([x00-xff]+)$" {
try_files $uri $uri/ /trnds/trend?name=$1;
}
...
}

让我详细解释一下。

  1. \x00-\xxf-它允许所有符号采用Unicode格式,不要忘记使用字符集UTF-8启用UTF-8;在服务器块中
  2. /trnds/-在Nginx的官方文档上(现在找不到它来发布链接(,他们有一点解释,如果我们在URL栏中有相同的地址,这个文件夹就不应该存在于服务器中

因此,我将try_files从/trends/更改为/trnds/,并对服务器上的文件夹进行重构,一切都很顺利!

最新更新