简体   繁体   中英

nginx reverse proxy to localhost

I have application running on my AWS EC2 Instance's localhost:8080.

In order to use these Web portal, I have install nginx on EC2 and reversed proxy localhost so that I can access Web UI on my browser.

Nginx.conf file

server {
    listen 80;
    server_name ec2-xx-xx-xxx-xxx.eu-central-1.compute.amazonaws.com;

    location / {
    proxy_pass http://localhost:8080;

   location /$request_uri {
   proxy_pass http://localhost$request_uri;

} 

}

When hitting EC2 URL on my browser,I successfully seeing homepage of application.

But when I hit any url let's say /admin, Nginx redirects to my local computer's localhost:8080/admin not Server's localhost. All i want is that when hit any url nginx should forward the request to localhost:8080{$URL} and return me the browser.

please suggest where I'm wrong. Thanks In Advance.

You don't need to add the second location.

location / {
    proxy_pass http://localhost:8080;
    proxy_set_header   Host $http_host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

this should be enough to access anything you need.

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