2017-12-03 106 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; 
    }