简体   繁体   English

Nginx和proxy_pass ip

[英]Nginx and proxy_pass ip

i've got little problem with nginx and proxy_pass on my VPS, the configuration look like this: 我的VPS上的nginx和proxy_pass没什么问题,配置看起来像这样:

server {

    listen 8080;
    root /var/www/;
    index index.php;

    location ~ \.php {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass wordpress;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            fastcgi_param QUERY_STRING      $query_string;
            include fastcgi_params;
    }

} }

server {
    listen 80;
    root /var/www;
    index index.html;

    location ~ ^/mihal {
            proxy_pass http://127.0.0.1:8080;
    }

    location ~ \.php {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass wordpress;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            fastcgi_param QUERY_STRING      $query_string;
            include fastcgi_params; 
    }

} }

and every time i've try to get the http://serverdomanin.com/mihal i've been redirected to http://127.0.0.1/mihal ... What should i moderate to corectly use this configuration? 并且每次我尝试获取http://serverdomanin.com/mihal时,我都已重定向到http://127.0.0.1/mihal ...我应该如何适当地使用此配置? (under /mihal/ is wordpress instance). (在/ mihal /下是wordpress实例)。 Many thanks for help! 非常感谢您的帮助!

The redirect is generated by the service running on port 8080, which does not know the name serverdomain.com . 重定向是由端口8080上运行的服务生成的,该服务不知道名称serverdomain.com

You can rewrite the redirect using the proxy_redirect directive. 您可以使用proxy_redirect指令重写重定向。

Try this: 尝试这个:

location ~ ^/mihal {
    proxy_pass http://127.0.0.1:8080;
    proxy_redirect http://localhost/ http://$host/;
    proxy_redirect http://localhost:8080/ http://$host/;
}

See this document for details. 有关详细信息,请参见此文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM