Skip to content

Using nginx as a reverse proxy

To set up Nginx as a reverse proxy:

1. Add a DNS Subdomain:

  1. Log into your DNS Management Console:
  2. For DirectAdmin, log in to your DirectAdmin control panel.

  3. Add a Subdomain Record:

  4. Go to the DNS management section.
  5. Look for an option to add a new record.
  6. Add a new record with the following details:
    • Type: A (for an A record that maps the subdomain to an IP address) or CNAME (if you want to point it to another domain).
    • Name: Enter the subdomain you want to create.
    • Value: Enter the IP address (for A records) or the domain (for CNAME records) where you want the subdomain to point.
  7. Save or apply the changes.

2. Testing the DNS Subdomain

Test using dig

  1. Open a Terminal or Command Prompt.

  2. Use the dig Command:

  3. To check the A record, use: bash dig subdomain.domain.com
  4. To check the CNAME record, use: bash dig subdomain.domain.com CNAME

Checking DNS Propagation

  1. Use DNS Propagation Tools:
  2. Visit online tools like DNS Checkeror WhatsMyDNS.
  3. Enter your subdomain and select the record type (A, CNAME, etc.).

Note: DNS changes can take time to propagate. Typically, this is up to 48 hours, but it often happens much faster.

2. Set up Nginx:

  • Configure the file: /etc/nginx/sites-available/subdomain.domain.com
nginx
   server {
       listen 80;
       server_name subdomain.domain.com;

       location / {
           proxy_pass http://server_ip:9000;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
       }
   }
  • Create a symlink: sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/

  • Teste Nginx configuration: sudo nginx -t

  • Reloade Nginx: sudo systemctl reload nginx