How to Configure a Proxy Server (Squid, Nginx)

A proxy server enhances security, improves performance, and helps manage traffic on your dedicated server. This guide will walk you through setting up a proxy server using Squid and Nginx on your dedicated server from QuickServers.


Step 1: Update Your Server

  • Ensure your server is running the latest software updates before installing a proxy server.
  • Run the following command based on your operating system:
    • Debian/Ubuntu: sudo apt update && sudo apt upgrade -y
    • CentOS/AlmaLinux/Rocky: sudo yum update -y

Setting Up a Squid Proxy Server

Step 2: Install Squid

  • Install Squid using the package manager:
    • Debian/Ubuntu: sudo apt install squid -y
    • CentOS/AlmaLinux/Rocky: sudo yum install squid -y

Step 3: Configure Squid

  • Open the Squid configuration file:
    • sudo nano /etc/squid/squid.conf
  • Modify the following settings:
    • Allow specific IPs to use the proxy (replace your-ip with your actual IP):
      acl allowed_clients src your-ip
      http_access allow allowed_clients
      
    • Set the proxy port (default is 3128):
      http_port 3128
      

Step 4: Restart Squid

  • Apply the changes by restarting Squid:
    • sudo systemctl restart squid
  • Enable Squid to start on boot:
    • sudo systemctl enable squid

Step 5: Verify Squid is Running

  • Check the Squid service status:
    • sudo systemctl status squid
  • Test the proxy by configuring a web browser or device to use your server's IP and port 3128.

Setting Up an Nginx Reverse Proxy

Step 6: Install Nginx

  • Install Nginx using the package manager:
    • Debian/Ubuntu: sudo apt install nginx -y
    • CentOS/AlmaLinux/Rocky: sudo yum install nginx -y

Step 7: Configure Nginx as a Proxy

  • Open the Nginx configuration file:
    • sudo nano /etc/nginx/sites-available/default
  • Add the following lines inside the server {} block to set up a reverse proxy:
    location / {
        proxy_pass http://your-backend-server-ip:80;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    
    • Replace your-backend-server-ip with the actual IP of the server you want to proxy traffic to.

Step 8: Restart Nginx

  • Apply the changes by restarting Nginx:
    • sudo systemctl restart nginx
  • Enable Nginx to start on boot:
    • sudo systemctl enable nginx

Step 9: Verify the Proxy Server is Working

  • Use a web browser or terminal to test the proxy:
    • curl -x http://your-server-ip:3128 http://example.com (For Squid)
    • curl -I http://your-server-ip (For Nginx)
  • If you receive a response from the backend server, your proxy is successfully configured.

By setting up Squid or Nginx, you can efficiently manage server traffic, improve security, and optimize performance.

Was this answer helpful? 0 Users Found This Useful (0 Votes)