I rent a ubuntu server from Digital Ocean, bought a domain name from Porkbun. I was hosting a nuxt project on localhost:3000
with pm2 one the server, used Nginx to proxy the port 80 to the localhost by configuring the /etc/nginx/sites-available/default file with the following code
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://localhost:3000;
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;
}
}
Now I would like to deploy another nuxt project on the same server, so I start a new app with pm2 on localhost:3001
, then i added and new server block on the nginx config with server_name dev.mydomain.com
and the proxy_pass HTTP://localhost:3001
However even no matter I add new DNS record on DigitalOcean or Porkbun, changing or adding the server_name
on both server block with mydomain.com
or dev.mydomain.com
, I can only access the port 3000 nuxt project with mydomain.com
I don't know how should I do the config, i did add CNAME record for redirecting www.mydomain.com on DigitalOcean and porkbun before which worked fine, yet I deleted these records for testing the dev.mydomain.com and all these www. / dev. will redirect to the localhost:3000 nuxt project with the following config.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name mydomain.com www.mydomain.com;
location / {
proxy_pass http://localhost:3000;
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;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name dev.mydomain.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;
}
}
Aucun commentaire:
Enregistrer un commentaire