为什么在NGINX中重写不起作用?

时间:2017-12-03 05:45:38

标签: php nginx

尝试在本地服务器上添加重写,但我被卡住了。

这就是我所拥有的。

location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        # try_files $uri $uri/ =404;
        try_files $uri $uri/ $uri.html $uri.php?$query_string;
    }

    location /news/post/ {
        rewrite ^/news/post/([a-zA-Z0-9-])?$ /news/post.php?id=$1 break;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
        #extra
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #--extra
    }

当进入/ news / post /它说"你选择打开这个文件"并询问我是否要下载BIN文件。

如果我去/ news / post / this-is-a-news-title我得到404 Not Found。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

作品。改变了一点,需要完整的路径。

location /news/post/ {
        rewrite ^/news/post/(.*)$ http://www.myserver.com/news/post.php?id=$1 break;
    }