{"id":3050,"date":"2025-11-16T12:28:29","date_gmt":"2022-08-15T13:30:17","guid":{"rendered":""},"modified":"2025-02-02T00:46:19","modified_gmt":"2025-02-01T23:46:19","slug":"how-to-install-apache-with-nginx-as-a-reverse-proxy-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-apache-with-nginx-as-a-reverse-proxy-on-ubuntu-22-04\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 Apache with Nginx as a Reverse Proxy on Ubuntu 22.04"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<\/header>\n<article>\n<p><strong>Apache<\/strong> and <strong>Nginx<\/strong> are two of the most widely used web servers, each offering unique strengths. Apache is known for its flexibility and extensive features, while Nginx excels in handling high loads and serving static content efficiently. By setting up Nginx as a reverse proxy for Apache on <strong>Ubuntu 22.04<\/strong>, you can leverage the strengths of both servers. Hosting this setup on a  ensures optimal performance, control, and scalability, which is ideal for growing websites or applications that require a robust infrastructure on a <strong>VPS server<\/strong>.<\/p>\n<h2>Step 1: Update Your VPS Server<\/h2>\n<p>Before installing Apache and Nginx, make sure your <a href=\"https:\/\/ie.netcloud24.com\">VPS server<\/a> is up to date. Run the following commands to update the package lists and upgrade the installed packages:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<p>By hosting your web application on a <strong>Windows VPS<\/strong>, you gain access to dedicated resources and better performance, ensuring smooth and reliable operation of your web server setup.<\/p>\n<h2>Step 2: Install Apache<\/h2>\n<p>First, install Apache, which will serve as the backend server:<\/p>\n<pre><code>sudo apt install apache2 -y<\/code><\/pre>\n<p>Once installed, start and enable Apache to run at boot:<\/p>\n<pre><code>\r\nsudo systemctl start apache2\r\nsudo systemctl enable apache2\r\n<\/code><\/pre>\n<p>To verify that Apache is running, open your browser and visit <code>http:\/\/your-server-ip<\/code>. You should see the default Apache welcome page.<\/p>\n<h2>Step 3: Install Nginx<\/h2>\n<p>Nginx will act as the reverse proxy, sitting in front of Apache and forwarding client requests. Install Nginx using the following command:<\/p>\n<pre><code>sudo apt install nginx -y<\/code><\/pre>\n<p>Once installed, start and enable Nginx:<\/p>\n<pre><code>\r\nsudo systemctl start nginx\r\nsudo systemctl enable nginx\r\n<\/code><\/pre>\n<h2>Step 4: Configure Nginx as a Reverse Proxy<\/h2>\n<p>Now, we will configure Nginx to act as a reverse proxy for Apache. Create a new server block configuration file:<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/apache-proxy<\/code><\/pre>\n<p>Add the following configuration, replacing <code>your-domain.com<\/code> with your actual domain or server IP address:<\/p>\n<pre><code>\r\nserver {\r\n    listen 80;\r\n    server_name your-domain.com;\r\n\r\n    location \/ {\r\n        proxy_pass http:\/\/127.0.0.1:8080;\r\n        proxy_set_header Host $host;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n        proxy_set_header X-Forwarded-Proto $scheme;\r\n    }\r\n\r\n    error_log \/var\/log\/nginx\/apache-proxy-error.log;\r\n    access_log \/var\/log\/nginx\/apache-proxy-access.log;\r\n}\r\n<\/code><\/pre>\n<p>This configuration tells Nginx to forward all traffic to Apache, which will listen on port 8080. Save the file and exit the editor.<\/p>\n<h2>Step 5: Configure Apache to Listen on Port 8080<\/h2>\n<p>By default, Apache listens on port 80. Since Nginx will be using port 80, we need to change Apache to listen on port 8080. Open the Apache ports configuration file:<\/p>\n<pre><code>sudo nano \/etc\/apache2\/ports.conf<\/code><\/pre>\n<p>Find the line that says <code>Listen 80<\/code> and change it to:<\/p>\n<pre><code>Listen 8080<\/code><\/pre>\n<p>Next, open the default Apache virtual host file to update the port:<\/p>\n<pre><code>sudo nano \/etc\/apache2\/sites-available\/000-default.conf<\/code><\/pre>\n<p>Find the <code>&lt;VirtualHost *:80&gt;<\/code> line and change it to:<\/p>\n<pre><code>&lt;VirtualHost *:8080&gt;<\/code><\/pre>\n<p>Save the file and exit the editor.<\/p>\n<h2>Step 6: Enable the Nginx Configuration<\/h2>\n<p>To activate the Nginx reverse proxy, enable the new configuration file:<\/p>\n<pre><code>\r\nsudo ln -s \/etc\/nginx\/sites-available\/apache-proxy \/etc\/nginx\/sites-enabled\/\r\n<\/code><\/pre>\n<p>Test the Nginx configuration for any syntax errors:<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p>If the test is successful, restart both Nginx and Apache to apply the changes:<\/p>\n<pre><code>\r\nsudo systemctl restart nginx\r\nsudo systemctl restart apache2\r\n<\/code><\/pre>\n<h2>Step 7: Verify the Setup<\/h2>\n<p>To verify that the reverse proxy setup is working correctly, open your browser and visit <code>http:\/\/your-domain.com<\/code> or your server&#8217;s IP address. You should see the Apache default page, meaning Nginx is correctly forwarding requests to Apache.<\/p>\n<h2>Step 8: Optimize Your VPS Server for Nginx and Apache<\/h2>\n<p>For the best performance and scalability, it is recommended to host this reverse proxy setup on a . A <strong>VPS server<\/strong> provides dedicated resources, allowing your setup to handle high traffic and efficiently serve dynamic content. By using a VPS, you can also scale your server as needed, ensuring that your web application can grow as your user base increases.<\/p>\n<h2>Conclusion<\/h2>\n<p>Setting up Nginx as a reverse proxy for Apache on Ubuntu 22.04 combines the strengths of both web servers, allowing you to serve static content quickly with Nginx while leveraging Apache for dynamic content. Hosting this setup on a  gives you improved performance, scalability, and control over your server environment, ensuring your website or application can handle any traffic demands.<\/p>\n<p>For more information on VPS hosting and optimizing your web server, visit  today.<\/p>\n<\/article>\n<footer>\n<p>\u00a9 2024 Windows VPS &#8211; All Rights Reserved<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 Apache and Nginx are two of the most widely used web servers, each offering unique strengths. Apache is known for its flexibility and extensive features, while\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-3050","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=3050"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3050\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=3050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=3050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=3050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}