Configuring Nginx for Test Sites
Let's use Nginx to bind domains to our test sites. To do this, let's open the configuration file, delete the current contents there and place the settings for our two sites there according to the following scheme:
server {
first site settings
}
server {
second site settings
}
Let's make the settings for the first site, specifying your domain name and your port on which the first site script is running:
server {
listen 80;
server_name test1.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Below in the same file, let's make the settings for the second site, also specifying the correct domain and port:
server {
listen 80;
server_name test2.com;
location / {
proxy_pass http://localhost:3002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
After that, let's execute the command that checks the configuration for errors:
nginx -t
Let's reload Nginx:
service nginx reload
Let's restart Nginx:
service nginx restart
Let's check the Nginx status (should be active, green text):
service nginx status
That's it, now you can go to the domains via the browser and they will lead to your test sites. If this doesn't happen, make sure that the A-records of the domains point to your server's IP, and also that you didn't mix up the ports of the sites deployed on NodeJS.
Bind domains to your test sites by configuring Nginx.
Visit your domains via a browser.