I'm trying to configure an Amazon EC2 instance running Amazon linux with nginx to serve two different ghost blogs in node.js.
My understanding is that web traffic hits the public IP of the ec2 instance, nginx is listening on port 80 and the config files for nginx reverse proxy each domain to the ports that the index.js file for each blog is listening for.
I'm using forever to run the two index.js files in the production environment but when I start both up, both domains (domain1.com & domain2.com) show the same content. It seems like starting the second index.js overwrites/redirects the traffic to the single ghost blog.
Maybe some of the configs might help:
Home folder
ls ~
domain2.com node domain1.com
Config.js for domain1.com
cat ~/domain1.com/config.js
production: {
url: 'http://www.domain1.com/',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
host: '127.0.0.1',
port: '2368'
}
},
Config.js for domain2.com
cat ~/domain2.com/config.js
production: {
url: 'http://domain2.com/',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
host: '127.0.0.1',
port: '2369'
}
}
Main nginx config
cat /etc/nginx/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name domain1.com *.domain1.com;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
nginx conf.d folder
ls /etc/nginx/conf.d/
domain2.com.conf virtual.conf
nginx domain2.com config
cat /etc/nginx/conf.d/domain2.com.conf
server {
listen 80;
listen [::]:80;
server_name domain2.com *.domain2.com;
root /var/www/html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2369;
}
}
How I'm starting the ghost blogs
cd ~/domain2.com/
NODE_ENV=production forever start index.js
cd ~/domain1.com/
NODE_ENV=production forever start index.js
Sorry for the super long first post. Thank you for the help in advance.