To configure Nginx to route a request from a subdomain, sub.xxx.com
, to localhost:8000
, you can follow these steps:
-
Open the Nginx configuration file for the domain, usually located at
/etc/nginx/sites-available/sub.xxx.com
. -
Add the following server block to the file:
server { listen 80; server_name sub.xxx.com; location / { proxy_pass http://localhost:8000; 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; } }
This server block listens on port
80
for requests tosub.xxx.com
, and proxies them tolocalhost:8000
using the proxy_pass directive. The proxy_set_header directives are used to set the necessary headers for the proxy server to forward the request correctly. -
Save the changes and exit the configuration file.
-
Test the Nginx configuration using the following command:
sudo nginx -t
This command checks the syntax of the configuration file and reports any errors.
-
If there are no errors, reload the Nginx service using the following command:
sudo systemctl reload nginx
This command reloads the Nginx configuration with the changes made.
With these steps, Nginx is configured to route requests from the subdomain sub.xxx.com
to localhost:8000
.