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

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

我在做什么错?

回答:

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

location /news/post/ { 

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

}

以上是 为什么在NGINX中重写这个不起作用? 的全部内容, 来源链接: utcz.com/qa/259653.html

回到顶部