Multiple nodebb sites on the same server
-
What should be the content of the nginx configuration file that I need to use to set up multiple nodebb sites on a server using a MongoDB database?
-
@kurulumu-Net said in Multiple nodebb sites on the same server:
What should be the content of the nginx configuration file that I need to use to set up multiple nodebb sites on a server using a MongoDB database?
Wowzers! Much depends on how you set them up. Do you favor the subdomains or sub folder approach? I personally prefer subdomains, e.g. "forums.yourdom.tld" - helps keep rewrite rules and such a big "cleaner".
Caveat emptor...
-
@gotwf I'm wondering how to setup multiple domains like forum.domain.com. I create two separate databases in MongoDb and set up two sites. When I type the domain name of the sites I set up in the browser, it sees that both sites use the same data. It's like two sites but one site.
This is how I create the database. I think it's wrong here.
> use admin > db.createUser( { user: "admin", pwd: "pass", roles: [ { role: "root", db: "admin" } ] } ) > use nodebb1 > db.createUser( { user: "nodebb1", pwd: "pass", roles: [ { role: "readWrite", db: "nodebb1" }, { role: "clusterMonitor", db: "admin" } ] } ) > use nodebb2 > db.createUser( { user: "nodebb2", pwd: "pass", roles: [ { role: "readWrite", db: "nodebb2" }, { role: "clusterMonitor", db: "admin" } ] } )
Nginx Conf file:
server { listen [::]:443 ssl ipv6only=on; listen 443 ssl; ssl_certificate /etc/ssl/cert.pem; ssl_certificate_key /etc/ssl/key.pem; ssl_client_certificate /etc/ssl/cloudflare.crt; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; server_name forum.domain.com; location / { 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; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:4567; proxy_redirect off; # Socket.IO Support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location /ads.txt { root /home/nodebb/nodebb/public/; } real_ip_header CF-Connecting-IP; set_real_ip_from 103.21.244.0/22; set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; set_real_ip_from 104.16.0.0/12; set_real_ip_from 108.162.192.0/18; set_real_ip_from 131.0.72.0/22; set_real_ip_from 141.101.64.0/18; set_real_ip_from 162.158.0.0/15; set_real_ip_from 172.64.0.0/13; set_real_ip_from 173.245.48.0/20; set_real_ip_from 188.114.96.0/20; set_real_ip_from 190.93.240.0/20; set_real_ip_from 197.234.240.0/22; set_real_ip_from 198.41.128.0/17; set_real_ip_from 2400:cb00::/32; set_real_ip_from 2606:4700::/32; set_real_ip_from 2803:f800::/32; set_real_ip_from 2405:b500::/32; set_real_ip_from 2405:8100::/32; set_real_ip_from 2c0f:f248::/32; set_real_ip_from 2a06:98c0::/29; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; } server { listen 80; listen [::]:80; ssl_certificate /etc/ssl/cert.pem; ssl_certificate_key /etc/ssl/key.pem; ssl_client_certificate /etc/ssl/cloudflare.crt; server_name forum.domain.com; return 301 https://forum.domain.com$request_uri; }
-
Have you selected different databases in the config.json
-
@kurulumu-Net Also, I presume you have properly configured DNS records?
-
It also looks like you only have one server block in your nginx config.
-
They are different scripts. Accordingly, they should have different database names, different ports, different nodebb services, different nginx conf files.
And preferably different users -
Steps:
- I create A record for two domains forum1.domain1.com and forum2.domain2.com for both forums. I confirm DNS forwarding.
- Create two different non-sudo users.
- Create two different databases in the first message.
- Make two separate nodeBB installations and enter separate database information for each installation.
- Create forum1.conf and forum2.conf nginx conf.
In the result browser both domains show the same nodebb instance.
As file path in Nginx conf file;
first site nginx.conf
server { listen [::]:443 ssl ipv6only=on; listen 443 ssl; ssl_certificate /etc/ssl/cert.pem; ssl_certificate_key /etc/ssl/key.pem; ssl_client_certificate /etc/ssl/cloudflare.crt; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; root /home/user1/nodebb/public; server_name forum1.domain1.com; . . .
first site nginx.conf
server { listen [::]:443 ssl ipv6only=on; listen 443 ssl; ssl_certificate /etc/ssl/cert2.pem; ssl_certificate_key /etc/ssl/key2.pem; ssl_client_certificate /etc/ssl/cloudflare.crt; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; root /home/user2/nodebb/public; server_name forum1.domain1.com; . . .
-
@kurulumu-Net forum 1 port 4567, forum2 port 45xx.
2 different platforms cannot use the same port -
@kurulumu-Net you can use nginx to listen on one port, but forward the traffic to two different ports based on the requested site.
-
nginx.confs
server { server_name serenitymc.net; location / { 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; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:4567; proxy_redirect off; # Socket.IO Support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } listen [::]:443 ssl ipv6only=on; listen 443 ssl; include serenitymc.ssl; } server { server_name onpu.serenitymc.net; location / { 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; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:4566; proxy_redirect off; # Socket.IO Support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } listen [::]:443 ssl; listen 443 ssl; include serenitymc.ssl; }
config.json
{ "url": "https://serenitymc.net", "secret": "xxx", "database": "mongo", "mongo": { "host": "127.0.0.1", "port": "27017", "username": "nodebb-serenity", "password": "xxx", "database": "nodebb-serenity" }, "port": "4567" } { "url": "https://onpu.serenitymc.net", "secret": "xxx", "database": "mongo", "mongo": { "host": "127.0.0.1", "port": "27017", "username": "nodebb-onpu", "password": "xxx", "database": "nodebb-onpu" }, "port": "4566" }