2017-12-03 129 views
-1

试图在本地服务器上添加重写,但我卡住了。为什么在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 
    } 

当去/新闻/职位/它说:“您已选择打开此文件”,并问我是否要下载一个BIN文件。

如果我去/ news/post /这是一个新闻标题,我会得到一个404 Not Found。

我在做什么错?

+0

堆栈溢出:为什么有人会投下一个问题?那有什么意义呢? –

回答

0

工程。改变了一下,需要完整的路径。

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