开发者

Nginx: set up proxy_path correctly. Problem with URLs

开发者 https://www.devze.com 2023-03-12 11:29 出处:网络
I have several servers running in virtual machines. And I have one running nginx for proxying requests to those servers. For example, http://mydomain.com/wiki shoul开发者_如何学JAVAd proxy request to

I have several servers running in virtual machines. And I have one running nginx for proxying requests to those servers. For example, http://mydomain.com/wiki shoul开发者_如何学JAVAd proxy request to http://192.168.122.3. 192.168.122.3 runs apache with DocumentRoot = /var/www/wiki. Everything works fine, but when page loads, all the paths there point to / instead of /wiki (like <img src="/bla-bla-bla"/>, not /wiki/bla-bla-bla"). It seems to be ok for apache, but not for browser - it can't load images etc. Changing DocumentRoot in apache to /var/www and passing /wiki from nginx doesn't help - mediawiki starts redirection to /wiki, nginx redirects it back to apache and so on before it says about looped redirections. The other projects runing in VMs like Redmine (ruby on rails) act the same.

Is there any way to solve this problem? Is there proper way to proxy URLs like /subdir to other servers?

This is nginx server section:

server {
    listen   192.168.122.7:80;
    server_name  mydomain.com;

    access_log  /var/log/nginx/localhost.access.log;

    location / {

    }
    location /wiki/ {
        proxy_pass http://192.168.122.3/;
    }
}


Your should use proxy_redirect directive.

location /wiki/ {
    proxy_pass http://192.168.122.3/;
    proxy_redirect default;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消