将规则重写为nginx conf

将规则重写为nginx conf,nginx,Nginx,我通过以下方式获得了.htaccess: 我需要将其转换为nginx conf,它非常简单,但我找不到 我试过: server { server_name ****; root /path; index index.html index.php; listen 80; # set expiration of assets to MAX for caching location ~* \.(ico|css|js|gif|jpe?g|png)(\?

我通过以下方式获得了.htaccess:

我需要将其转换为nginx conf,它非常简单,但我找不到

我试过:

server {
    server_name ****;
    root /path;

    index index.html index.php;
    listen 80;

    # set expiration of assets to MAX for caching
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
        expires max;
        log_not_found off;
    }

    location / {
      if (!-e $request_filename){
        rewrite ^(.+)$ /index.php?url=$1 break;
      }
    }

    location ~* \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
但它下载文件而不是显示它。我不明白

如果我使用:

http://example.com/index.php?url=login
但不包括:

http://example.com/login
好的,它使用:

location / {
    try_files $uri $uri/ /index.php?url=$uri;
}   

这可能与您的问题无关,但与此配置请求
http://example.com/login
被重写为
http://example.com/index.php?url=/login
。Change
rewrite^(+)$/index.php?url=$1 break
to
rewrite^/(.+)$/index.php?url=$1 break并测试它。如果我这样做,我有404错误
http://example.com/login
我觉得您的配置似乎正确。你能试试重写^(+)$/index.php吗?url=$1重定向,运行
curl-Ihttp://example.com/login
并通过此处的
位置
标题内容?
location / {
    try_files $uri $uri/ /index.php?url=$uri;
}