Nginx New Website / IP Configuration

Complete Step-by-Step Production Configuration Guide

Purpose: This guide explains how to configure a new website, subdomain, backend service, IP address, SSL certificate, reverse proxy, CORS, firewall and production verification using Nginx.

1Understand the Architecture

Suppose you want to configure a new website:

Component Example
Domain newservice.fortresscareer.com
Public Server IP 103.5.85.49
Nginx 443
Spring Boot 127.0.0.1:8083
SSL Let's Encrypt
Browser | | https://newservice.fortresscareer.com | v DNS | | 103.5.85.49 | v Nginx :443 | | proxy_pass | v Spring Boot :8083 | v Database / Other Services
Recommended security model: Only Nginx should normally be publicly exposed. Backend applications should preferably listen on 127.0.0.1.

2Decide Configuration Parameters

Item Example
Domain newservice.fortresscareer.com
Public IP 103.5.85.49
Nginx Port 443
Application Port 8083
Application IP 127.0.0.1

Spring Boot configuration:

server.port=8083

Or YAML:

server:
  port: 8083

3Verify Spring Boot Backend

Always verify the backend before configuring Nginx.

curl http://127.0.0.1:8083

For an API:

curl http://127.0.0.1:8083/api/test

Check whether the port is listening:

sudo ss -lntp | grep 8083
Expected:
LISTEN ... 127.0.0.1:8083 ...
Important: Prefer 127.0.0.1:8083 rather than 0.0.0.0:8083 when the backend does not need direct public access.

4Configure DNS

Create an A record at your DNS provider.

Type:   A
Name:   newservice
Value:  103.5.85.49
TTL:    300

The resulting mapping should be:

newservice.fortresscareer.com
            |
            v
      103.5.85.49

Verify DNS:

dig newservice.fortresscareer.com

Or:

nslookup newservice.fortresscareer.com
Configure and verify DNS before requesting the SSL certificate.

5Check Existing Nginx Configuration

sudo nginx -t

Display complete Nginx configuration:

sudo nginx -T

View enabled websites:

ls -la /etc/nginx/sites-enabled/

View available websites:

ls -la /etc/nginx/sites-available/

6Understand Nginx Directories

/etc/nginx/ | +-- nginx.conf | +-- sites-available/ | | | +-- apigateway.fortresscareer.com | +-- newservice.fortresscareer.com | +-- sites-enabled/ | +-- apigateway.fortresscareer.com +-- newservice.fortresscareer.com

Typically:

  • sites-available contains website configurations.
  • sites-enabled contains enabled configurations.

7Take Backup Before Changes

Example:

sudo cp /etc/nginx/sites-enabled/apigateway.fortresscareer.com \
/etc/nginx/sites-enabled/apigateway.fortresscareer.com.bak

Full Nginx backup:

sudo cp -r /etc/nginx \
/etc/nginx_backup_$(date +%Y%m%d_%H%M%S)
Always keep a backup before making production Nginx changes.

8Create Nginx Configuration

Go to:

cd /etc/nginx/sites-available

Create the configuration:

sudo nano newservice.fortresscareer.com

Initial HTTP configuration:

server {
    listen 80;

    server_name newservice.fortresscareer.com;

    location / {
        proxy_pass http://127.0.0.1:8083;
        proxy_http_version 1.1;

        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;
    }
}

9Enable the Website

sudo ln -s \
/etc/nginx/sites-available/newservice.fortresscareer.com \
/etc/nginx/sites-enabled/newservice.fortresscareer.com

Verify:

ls -l /etc/nginx/sites-enabled/

You should see something similar to:

newservice.fortresscareer.com
    ->
/etc/nginx/sites-available/newservice.fortresscareer.com

10Test Nginx Configuration

Never reload Nginx before testing the configuration.
sudo nginx -t

Expected:

syntax is ok
test is successful

Then reload:

sudo systemctl reload nginx

11Test HTTP

curl -I http://newservice.fortresscareer.com

Or:

curl http://newservice.fortresscareer.com

Also test backend directly:

curl http://127.0.0.1:8083
curl 127.0.0.1:8083 | v Spring Boot curl newservice.fortresscareer.com | v DNS + Nginx + Spring Boot

12Configure SSL

Check Certbot:

certbot --version

Request SSL:

sudo certbot --nginx \
-d newservice.fortresscareer.com

Certificate files normally appear under:

/etc/letsencrypt/live/newservice.fortresscareer.com/

fullchain.pem
privkey.pem

13Final HTTPS Nginx Configuration

server {
    server_name newservice.fortresscareer.com;

    location / {

        proxy_pass http://127.0.0.1:8083;
        proxy_http_version 1.1;

        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;
    }

    listen 443 ssl;

    ssl_certificate
        /etc/letsencrypt/live/newservice.fortresscareer.com/fullchain.pem;

    ssl_certificate_key
        /etc/letsencrypt/live/newservice.fortresscareer.com/privkey.pem;
}

Test:

sudo nginx -t

Reload:

sudo systemctl reload nginx

14CORS Configuration

If the frontend is:

https://ots.fortresscareer.com

and calls:

https://newservice.fortresscareer.com

you may need CORS configuration.

server {
    server_name newservice.fortresscareer.com;

    location / {

        if ($request_method = OPTIONS) {
            add_header 'Access-Control-Allow-Origin'
                'https://ots.fortresscareer.com' always;

            add_header 'Access-Control-Allow-Methods'
                'GET, POST, PUT, DELETE, OPTIONS' always;

            add_header 'Access-Control-Allow-Headers'
                'Authorization, Content-Type' always;

            add_header 'Access-Control-Allow-Credentials'
                'true' always;

            return 204;
        }

        proxy_pass http://127.0.0.1:8083;
        proxy_http_version 1.1;

        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;

        add_header 'Access-Control-Allow-Origin'
            'https://ots.fortresscareer.com' always;

        add_header 'Access-Control-Allow-Credentials'
            'true' always;
    }

    listen 443 ssl;

    ssl_certificate
        /etc/letsencrypt/live/newservice.fortresscareer.com/fullchain.pem;

    ssl_certificate_key
        /etc/letsencrypt/live/newservice.fortresscareer.com/privkey.pem;
}
Do not use * for Access-Control-Allow-Origin when credentials/cookies are required.

15Firewall / Port Security

Check UFW:

sudo ufw status

If UFW is enabled, normally allow:

sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Avoid unnecessarily exposing backend ports such as:

8080
8081
8082
8083
The preferred production design is:
Internet
   |
  443
   |
 Nginx
   |
127.0.0.1:8083
   |
Spring Boot

16Check Listening Ports

sudo ss -lntp

Example:

LISTEN ... 127.0.0.1:8080
LISTEN ... 127.0.0.1:8081
LISTEN ... 127.0.0.1:8082
LISTEN ... 127.0.0.1:8083
LISTEN ... 0.0.0.0:80
LISTEN ... 0.0.0.0:443
This means Nginx is exposed publicly while the backend services remain internal to the server.

17Nginx Logs

Access Log

sudo tail -f /var/log/nginx/access.log

Error Log

sudo tail -f /var/log/nginx/error.log

Systemd Logs

sudo journalctl -u nginx -f

Keep the logs open while testing a request from the browser.

18Common Problems and Fixes

Problem Likely Cause
502 Bad Gateway Backend unavailable or wrong port
404 Not Found Wrong URL or context path
403 Forbidden Permissions or Nginx configuration
400 Bad Request Request/Host mismatch
504 Gateway Timeout Backend taking too long
SSL Error DNS/certificate mismatch
CORS Error Incorrect CORS configuration
nginx [emerg] Configuration syntax problem
Connection Refused Backend is not listening

502 Troubleshooting

curl http://127.0.0.1:8083

Then:

sudo ss -lntp | grep 8083

If localhost itself fails, the problem is most likely with Spring Boot rather than Nginx.

19Understand proxy_pass

For:

https://newservice.fortresscareer.com/api/users

with:

location / {
    proxy_pass http://127.0.0.1:8083;
}

Nginx forwards the request to the backend while preserving the URI path.

Avoid unnecessary path transformations such as rewrite or StripPrefix until they are actually required.

20Spring Boot Context Path

Suppose your application has:

server.servlet.context-path=/newservice

Then the backend endpoint may be:

http://127.0.0.1:8083/newservice/api/users

Test the backend directly:

curl http://127.0.0.1:8083/newservice/api/users
Always make the backend endpoint work first. Then configure Nginx around that working endpoint.

21SSL Certificate Renewal

Check certificates:

sudo certbot certificates

Test renewal:

sudo certbot renew --dry-run
Always verify that automatic renewal is working for production websites.

22Complete New Website Procedure

1. Decide Domain
↓
2. Decide Backend Port
↓
3. Start Spring Boot
↓
4. Test localhost
↓
5. Configure DNS
↓
6. Verify DNS
↓
7. Create Nginx Configuration
↓
8. Enable Configuration
↓
9. nginx -t
↓
10. Reload Nginx
↓
11. Test HTTP
↓
12. Generate SSL
↓
13. Configure HTTPS
↓
14. Test HTTPS
↓
15. Test CORS
↓
16. Check Logs
↓
17. Verify SSL Renewal

23Your Existing Architecture

INTERNET | | HTTPS :443 | v +---------------------------+ | NGINX | | SSL TERMINATION | +---------------------------+ | +--------------+--------------+ | | | v v v :8080 :8081 :8082 / :8083 API Gateway Orchestrator Other Services | v Microservices | v Database

API Gateway Flow

https://apigateway.fortresscareer.com | v Nginx :443 | v 127.0.0.1:8080 | v API Gateway | v Orchestrator | v Database

24Existing Backup Commands

Orchestrator

sudo cp /etc/nginx/sites-enabled/orchestrator.fortresscareer.com \
/etc/nginx/sites-enabled/orchestrator.fortresscareer.com.bak

Governance

sudo cp /etc/nginx/sites-enabled/governance.fortresscareer.com \
/etc/nginx/sites-enabled/governance.fortresscareer.com.bak

Auth Service

sudo cp /etc/nginx/sites-enabled/authservice.fortresscareer.com \
/etc/nginx/sites-enabled/authservice.fortresscareer.com.bak

Delivery Service

sudo cp /etc/nginx/sites-enabled/deliveryservice.fortresscareer.com \
/etc/nginx/sites-enabled/deliveryservice.fortresscareer.com.bak

SFTP Service

sudo cp /etc/nginx/sites-enabled/sftpservice.fortresscareer.com \
/etc/nginx/sites-enabled/sftpservice.fortresscareer.com.bak

25Production Checklist

  • Spring Boot service is running
  • Correct backend port identified
  • Backend tested using 127.0.0.1
  • DNS A record created
  • DNS resolves to correct public IP
  • Nginx configuration created
  • Nginx configuration enabled
  • sudo nginx -t successful
  • Nginx reloaded
  • HTTP tested
  • SSL certificate created
  • HTTPS tested
  • Backend remains bound to localhost
  • Ports 8080/8081/8082/8083 are not unnecessarily exposed
  • CORS tested from frontend
  • Nginx access logs checked
  • Nginx error logs checked
  • Spring Boot logs checked
  • certbot renew --dry-run successful

26Important Commands Cheat Sheet

Check Nginx

sudo nginx -t

Reload Nginx

sudo systemctl reload nginx

Restart Nginx

sudo systemctl restart nginx

Nginx Status

sudo systemctl status nginx

Enabled Sites

ls -la /etc/nginx/sites-enabled/

Available Sites

ls -la /etc/nginx/sites-available/

Check Ports

sudo ss -lntp

Nginx Error Log

sudo tail -f /var/log/nginx/error.log

Nginx Access Log

sudo tail -f /var/log/nginx/access.log

DNS Check

dig newservice.fortresscareer.com

Backend Test

curl http://127.0.0.1:8083

HTTPS Test

curl -I https://newservice.fortresscareer.com

Check Certificates

sudo certbot certificates

Test Certificate Renewal

sudo certbot renew --dry-run

Final Recommended Production Flow

Browser | | HTTPS :443 v +-------------------+ | NGINX | | SSL Termination | +-------------------+ | | proxy_pass v +-------------------+ | Spring Boot App | | 127.0.0.1:8083 | +-------------------+ | v +-------------------+ | Other Services | +-------------------+ | v Database
Golden Rule:

DNS → Backend → Nginx HTTP → SSL → HTTPS → CORS → Logs → Security
Most important practice: First make sure curl http://127.0.0.1:PORT works. Then configure Nginx. This makes troubleshooting significantly easier.