2014-01-23 19 views
3

转发我在端口80我的主机端口转发8080无业游民虚拟机的端口上运行Nginx的80nginx的301下降的流浪汉

我需要重写一个URL 301重定向,流浪汉虚拟机端口,工程,但我用来通过隧道(8080)访问nginx的端口被丢弃,重定向失败。

http://server.com:8080/blog/two 

-becomes-

http://server.com/blog.php?article=two 

- 它应该是 -

http://server.com:8080/blog.php?article=two 

例如:

rewrite ^/blog/(.*)$ /blog.php?article=$1 last; 

谢谢!

+0

重写^ /博客/(.*)$ HTTP://$http_host/blog.php文章= $ 1的最近; [请告诉我主机和HTTP_HOST在nginx的的差] [1] [1]:http://stackoverflow.com/questions/15414810/whats-the-difference-of-host-and-http-host -in-nginx – user3228313

+0

如果你不想要端口8080,那么为什么nginx要监听8080端口而不是80端口,或者我理解错了 –

回答

0

摘自Host头字段原来的端口号:

set $port ''; 

if ($http_host ~ :(\d+)$) { 
    set $port :$1; 
} 

rewrite ^/blog/(.*)$ http://example.com$port/blog.php?article=$1;