简体   繁体   中英

Nginx and proxy_pass ip

i've got little problem with nginx and proxy_pass on my VPS, the configuration look like this:

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? (under /mihal/ is wordpress instance). Many thanks for help!

The redirect is generated by the service running on port 8080, which does not know the name serverdomain.com .

You can rewrite the redirect using the proxy_redirect directive.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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