Nginx is a free, open-source, lightweight, and high-performance web server around the world. It is specially designed to address the performance limitations of Apache web servers. It uses an event-driven architecture and can handle multiple requests within one thread. Generally, Nginx is often used as a reverse proxy or caching service. Nginx reverse proxy is a proxy service that directs client requests to one or more backend servers. You can use Nginx reverse proxy for various protocols such as HTTP, HTTPS, TCP, UDP, SMTP, IMAP, and POP3.
Load Balancing – A reverse proxy server sits in front of multiple backend servers and distributes clients requests across multiple servers. This will improve the website speed and capacity utilization. If one server goes down, the load balancer will redirects traffic to another server.
Security – A reverse proxy server provides an additional defense against security attacks by hiding the identity of backend servers.
Performance – A reverse proxy server can cache the common content and compress the inbound and outbound data, which will drastically improve the connection speed between client and server.
In this guide, we will explain how to configure an Nginx reverse proxy in front of an Apache webserver on Ubuntu.
To verify the Apache web server, open your web browser and type the URL http://your-server-ip:8080 in the address bar. You should see the Apache default page in the following screen:
Save and close the file then verify the Nginx for any configuration error using the following command:
nginx -t
Sample output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Next, reload the Nginx service to apply the configuration changes:
systemctl reload nginx
You can check the status of the Nginx service using the following command:
systemctl status nginx
If everything is fine, you should see the following output:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-09-06 07:33:12 UTC; 5s ago
Docs: man:nginx(8)
Process: 17460 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 17461 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 17462 (nginx)
Tasks: 2 (limit: 2341)
Memory: 2.4M
CPU: 50ms
CGroup: /system.slice/nginx.service
├─17462 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─17463 nginx: worker process
Sep 04 07:33:12 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 04 07:33:12 ubuntu systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Sep 04 07:33:12 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.
At this point, Nginx has been configured as a front-end server for Apache. Now it’s time to verify whether the Nginx passes the requests to the Apache webserver.
Open the command-line terminal interface and run the following command to test the Nginx proxy:
curl -I http://proxy.example.com
If everything is fine, you should get the following output:
You can also test the Nginx proxy using the URL http://proxy.example.com in your web browser. If everything is fine, you should see the Apache backend server default page as shown below:
How to Setup Nginx as Reverse Proxy On Ubuntu Server Conclusion
In this guide, we explained how to install and configure Apache as a backend server on port 8080. Then, we explained how to configure Nginx as a reverse proxy to pass the client’s request to the Apache backend server. I hope you have now enough understanding of how Nginx reverse proxy works.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.