Configuring Domain Names for Node.js, Vue SPA, and SSR Applications
Domain Name Registration
Register a domain name through a domain registrar such as Tencent Cloud.
DNS Record Configuration
Configure DNS records in your domain management panel to point the domain to your server's IP address.
Nginx Server Block Setup
Naivgate to the Nginx configuration directroy:
cd /usr/local/lighthouse/softwares/nginx/conf/web
Vue Single-Page Application Configuration
server {
listen 80;
server_name admin.example.com;
charset utf-8;
location / {
root /home/node/nodejs-koa-blog/admin-blog/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
Server-Side Rendered Application Configuration
server {
listen 80;
server_name blog.example.com;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Nginx-Proxy true;
proxy_cache_bypass $http_upgrade;
proxy_pass http://localhost:3001/;
}
}
Node.js API Service Configuration
server {
listen 80;
server_name api.example.com;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Nginx-Proxy true;
proxy_cache_bypass $http_upgrade;
proxy_pass http://localhost:9000/;
}
}
Nginx Configuration Validation
Test the configuration syntax:
nginx -t
Reload Nginx to apply changes:
nginx -s reload
Access Verification
Verify the appplications are accessible via their respective domains:
- SPA Application: http://admin.example.com/
- SSR Application: http://blog.example.com/
- API Endpoint: http://api.example.com/api/v1/category