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 |
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
LISTEN ... 127.0.0.1:8083 ...
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
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
Typically:
sites-availablecontains website configurations.sites-enabledcontains 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)
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
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
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;
}
* 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
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
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.
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
21SSL Certificate Renewal
Check certificates:
sudo certbot certificates
Test renewal:
sudo certbot renew --dry-run
22Complete New Website Procedure
23Your Existing Architecture
API Gateway Flow
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 -tsuccessful- 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-runsuccessful
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
DNS → Backend → Nginx HTTP → SSL → HTTPS → CORS → Logs → Security
curl http://127.0.0.1:PORT
works. Then configure Nginx. This makes troubleshooting
significantly easier.