我在端口8080,8090有不同的webistes服务
现在我唯一允许的港口是外面的8085。
有没有可能做到这一点
myserver.com:8085/site1 go to 8080 myserver.com:8085/site2 go to 8090
我要那个
http://www.myserver.com:8085/site1应该去http://myserver.com:8080/site1
Tim编辑 – 从下面的OP问题中添加
我也想
/site1/task
代理到http://example.com:5678/task
我试过这个
location ~ ^/site2(/)?(?<var>\w+)? { proxy_pass http://127.0.0.1:3434/$var; }
像这样的东西应该工作 – 这只是光秃秃的骨头。 这不是一个专业的问题,但这是Nginx的一个绝对的基础,你应该能够用一个简单的教程来自己动手。
server { server_name example.com; listen 8085; location /site1 { proxy_pass http://example.com:8080; } location /site1/task { proxy_pass http://example.com/task:8090; } location /site2 { proxy_pass http://example.com:8090; } # If you want a variable in the location, something like this might work # This is a regular expression with a capture group, untested, which # should at least give you a good clue how to work it out yourself location ~/site3/([0-9a-zA-Z_\-\s\+]+)$) { proxy_pass http://example.com/$1; } }