VHosts and Directives, Part 5: Location Directive and Proxy_Pass in nginx

Location Directive and Proxy Pass in nginx

We can configure our server to send portion of our request to a proxy server and other portions to a different proxy server

1.) Move to nginx configuration files directory.

cd /etc/nginx/vhost.d

2.) Add following code inside server block of your domain congiguration file

location / {
root /var/www/html/myexample;
location /google/ {
proxy_pass http://www.google.com/;


proxy_pass: The request is forwarded to the URL given by the directive when a request matches a location with a proxy pass directive.

forexample in this case if you open http://myexample.local/google proxy_pass directive will forward your request to google search

3.) Use following command to make sure that you haven’t made any typos or added any invalid entries.

nginx -t

4.) Restart the Service

systemctl restart nginx.service

5.) Video Tutorial

Have questions, post them in the comments.

Add Comment