Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Nginx as Reverse Proxy
coder7475
coder7475

Posted on

Nginx as Reverse Proxy

Reverse Proxy

A reverse proxy sits in front of a server and can

  • Act as Load Balancer
  • Protect the origin servers from attacks by hiding it's IP addresses
  • Cache content for faster performance
  • Provide SSL encryption and decryption to and from the server

Directive Needed

Nginx usesproxy_pass Directive for configuring reverse proxy.

  location /{    proxy_pass http://10.1.1.3:9000/app1}
Enter fullscreen modeExit fullscreen mode

Nginx uses proxy_pass directory to pass the request to 'example.com' to another server with ip address of10.1.1.3:9000.

Important: When nginx starts connection with another server(backend) with proxy pass. Itcloses the previous connection with the client which results in some request information islost. So one shouldcapture the original details like actual ip address of client, host details etc andforward to the backend server.

Forward client details to backend server via reverse proxy

One need to Redefining Request Headers and forward it to backend server. To redefine request header useproxy_set_header.

Use proxy_set_header

  • Syntax: proxy_set_header ;
  server{    listen 80;    proxy_set_header Host$host;# replaces host header that comes from client    proxy_set_header X-Real-IP$remote_addr;# captures original ip address of requester and sends it to backend    proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;# all the traverse route the request takes    location /{      proxy_pass http://10.1.1.3:9000/app1}}
Enter fullscreen modeExit fullscreen mode

References

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a Software Engineer focusing on web development. I am currently exploring the world of DevOps Engineering.
  • Joined

More fromcoder7475

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp