Installing NodeBB in a subfolder of another site

Technical Support
  • @baris

    The last time I tried subfolder installation it was working fine, but I never tried it with nginx proxying.

    Accessing it from a subfolder with the port appended is not a problem, but that's not feasible for a public site,

    And what do you make of the error messages from Chrome console below?

    GET http://192.168.1.4/forum/404 404 (Not Found) 192.168.1.4/:25
    Uncaught ReferenceError: io is not defined nodebb.min.js:7
    Uncaught TypeError: Cannot set property 'initialLoad' of undefined 192.168.1.4/:270
    Uncaught ReferenceError: templates is not defined nodebb.min.js:8
    Uncaught TypeError: Cannot call method 'emit' of undefined 
    

    And what do you make of the fact that NodeBB is listening on the default port even after specifying during the installation stage that it not listen to the port. Could that be part of the problem?

  • I have found the best solution for me.

    I use the redirect rules in iptables of my cloud Ubuntu14.04.
    The comand below will redirect port 80 to port 3000. Use your NodeBB at port 3000

    sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
    

    The comand above will works up to next reboot. It means that you have to add the following string to
    ** /etc/rc.local file **

    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
    

    Important

    Check if your network interface use the name eth0. Perhaps you have to use other network interface (for example eth1... etc)

  • Has there been any advancement about displaying nodebb from .com/forum using nginx ?

  • @limitx3m said:

    Has there been any advancement about displaying nodebb from .com/forum using nginx ?

    I would be interested too

  • Hey, noob here.

    I'm looking at this myself has anyone made any progress?

    I got setup yesterday, redirected to /forum using nginx, now need to fix the base url in html and I think may be onto something.

    Thanks

    Dave

  • Actually yeah I've managed to install it in a subdirectory and run it via normal command line but I've got problems trying to get it to restart on reboot.

    nginx/site-available/nodebb

    	server {
    		listen 80 default_server;
    		listen [::]:80 default_server;
    		root /var/www/;
    		index index.html index.htm index.nginx-debian.html;        
    		server_name _;
    		location / {
    			# First attempt to serve request as file, then
    			# as directory, then fall back to displaying a 404.
    			try_files $uri $uri/ =404;
    		}
    		location /forum {
    			proxy_set_header X-Real-IP $remote_addr;
    			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    			proxy_set_header Host $http_host;
    			proxy_set_header X-NginX-Proxy true;
    
    			proxy_pass http://127.0.0.1:4567/forum;
    			proxy_redirect off;
    
    			# Socket.IO Support
    			proxy_http_version 1.1;
    			proxy_set_header Upgrade $http_upgrade;
    			proxy_set_header Connection "upgrade";
    	    }
    
    	}
    

    config.json

    	{
    	    "url": "http://localhost:4567/forum",
    	    "secret": "insert_your_secret_here",
    	    "database": "redis",
    	    "redis": {
    	        "host": "127.0.0.1",
    	        "port": "6379",
    	        "password": "insert_your_password_here",
    	        "database": "0"
    	    }
    	}
    

    In order to restart nodebb upon server restart I've used the init script based on
    https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/

    Modifications/Important config below

    SOURCE_DIR="/var/www/nodebb"
    NODE_USER="nodejs_user";
    APPLICATION_PATH="app.js"
    
    #  ... other config 
    start() {
        echo "Starting $NAME"
        #  sample forever command didn't seem to work
        #    forever 
        #      --pidFile $PIDFILE 
        #      -a 
        #      -l $LOGFILE 
        #      --minUptime $MIN_UPTIME 
        #      --spinSleepTime $SPIN_SLEEP_TIME 
        #      start $APPLICATION_PATH 2>&1 > /dev/null &
    
        sudo -u $NODE_USER relative_path=/forum upload_url=/forum/uploads/ forever --sourceDir $SOURCE_DIR --pidFile $PIDFILE -a -l $LOGFILE --minUptime $MIN_UPTIME --spinSleepTime $SPIN_SLEEP_TIME start $APPLICATION_PATH 2>&1 > /dev/null &
    

    Not sure if that's the best way of doing it, but it seemed to work for me.

    Edit: Seems that file/image upload is broken: it uploads to /uploads/ instead of /forum/uploads/. Still looking into that

    Edit 2: Uploads fixed with relative_path=/forum upload_url=/forum/uploads/ in the script. Other problems found:

    • Can't stop forever via script (maybe something to do with log and pidfiles not being created)
    • Can't install plugins
    • Doesn't read from config.json but via environment variables passed in the init/forever script?
  • I forked your topic so you will not be inadvertently resurrecting an old topic.

    In my nginx config, I have the following lines that differ from yours:

    location /forum/ {
    

    and

    proxy_pass http://127.0.0.1:4567/forum/;
    

    Perhaps altering those lines will help.

  • @julian said in Installing NodeBB in a subfolder of another site:

    I forked your topic so you will not be inadvertently resurrecting an old topic.

    In my nginx config, I have the following lines that differ from yours:

    location /forum/ {
    

    and

    proxy_pass http://127.0.0.1:4567/forum/;
    

    Perhaps altering those lines will help.

    config.json should be:

    "url": "http://domain.com/forum",

    nginx.conf should be:

      location ^~ /forum { 
            proxy_pass http://127.0.0.1:4567;
     }
    

    ^~ /forum is important, not /forum

  • @Violing ^~ is a regular expression override. If you require that, you are using a poorly written regular expression elsewhere in your config.

  • @Violing

    I was able to make it work with /forum; no ^~ required. Given what @yariplus stated this seems relevant.
    My conf:

    location /forum/ {
          proxy_pass http://172.17.2.3:4567;
          proxy_redirect off;
          proxy_set_header Host $http_host;
           proxy_set_header X-Forwarded-Host $host;
           proxy_set_header X-Forwarded-Server $host;
          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 X-NginX-Proxy true;
    
          # Socket.IO Support
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
       }
    

    Indented lines are ones that I copied from my other blocks that weren't present in the suggested.


Suggested Topics


  • 0 Votes
    1 Posts
    450 Views

    Hey there!

    I have a nodebb instance i've been customizing through theming and plugins.

    I recently came across an issue that has prevented me from running ./nodebb start

    Clustering enabled: Spinning up 4 process(es).

    2019-07-22T06:23:35.139Z [4567/15633] - info: Initializing NodeBB v1.12.2 https://kratomwatchdog.com 2019-07-22T06:23:35.431Z [4567/15633] - error: NodeBB could not connect to your Mongo database. Mongo returned the following errorconnect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"],"stack":"MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017\n at Socket.err (/home/ubuntu/nodebb/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connect.js:287:16)\n at Object.onceWrapper (events.js:315:30)\n at emitOne (events.js:116:13)\n at Socket.emit (events.js:211:7)\n at emitErrorNT (internal/streams/destroy.js:66:8)\n at _combinedTickCallback (internal/process/next_tick.js:139:11)\n at process._tickCallback (internal/process/next_tick.js:181:9)"} 2019-07-22T06:23:35.443Z [4567/15633] - error: connect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]} 2019-07-22T06:23:35.446Z [4568/15638] - error: NodeBB could not connect to your Mongo database. Mongo returned the following errorconnect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"],"stack":"MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017\n at Socket.err (/home/ubuntu/nodebb/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connect.js:287:16)\n at Object.onceWrapper (events.js:315:30)\n at emitOne (events.js:116:13)\n at Socket.emit (events.js:211:7)\n at emitErrorNT (internal/streams/destroy.js:66:8)\n at _combinedTickCallback (internal/process/next_tick.js:139:11)\n at process._tickCallback (internal/process/next_tick.js:181:9)"} 2019-07-22T06:23:35.448Z [4568/15638] - error: connect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]} 2019-07-22T06:23:35.449Z [4569/15640] - error: NodeBB could not connect to your Mongo database. Mongo returned the following errorconnect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"],"stack":"MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017\n at Socket.err (/home/ubuntu/nodebb/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connect.js:287:16)\n at Object.onceWrapper (events.js:315:30)\n at emitOne (events.js:116:13)\n at Socket.emit (events.js:211:7)\n at emitErrorNT (internal/streams/destroy.js:66:8)\n at _combinedTickCallback (internal/process/next_tick.js:139:11)\n at process._tickCallback (internal/process/next_tick.js:181:9)"} [cluster] Child Process (15633) has exited (code: 0, signal: null) 2019-07-22T06:23:35.454Z [4569/15640] - error: connect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]} [cluster] Child Process (15638) has exited (code: 0, signal: null) [cluster] Child Process (15640) has exited (code: 0, signal: null) 2019-07-22T06:23:35.462Z [4570/15645] - error: NodeBB could not connect to your Mongo database. Mongo returned the following errorconnect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"],"stack":"MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017\n at Socket.err (/home/ubuntu/nodebb/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connect.js:287:16)\n at Object.onceWrapper (events.js:315:30)\n at emitOne (events.js:116:13)\n at Socket.emit (events.js:211:7)\n at emitErrorNT (internal/streams/destroy.js:66:8)\n at _combinedTickCallback (internal/process/next_tick.js:139:11)\n at process._tickCallback (internal/process/next_tick.js:181:9)"} 2019-07-22T06:23:35.464Z [4570/15645] - error: connect ECONNREFUSED 127.0.0.1:27017 {"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]} [cluster] Child Process (15645) has exited (code: 0, signal: null)

    I am able to run nodebb in dev mode, and have had to run it in a screens session to keep the forum online until i'm able to resolve the issue.

  • 0 Votes
    4 Posts
    779 Views

    OK... removing the port, :4567 - helped with the Google SSO to finally work.

    just "https://digital.nomadic.cloud" - and it's working fine.

    I know that during the set up process (tried 5 times previously), ensuring the port here made a difference with making something else work.

    When I see that bug again, I will post that separately.

    and.. thank you ๐Ÿ™‚

  • 0 Votes
    3 Posts
    1k Views

    @pitaj said in Many NodeBB forums have a message... connection... lost...:

    The "connection lost" message is usually caused because the URL at which you are visiting a NodeBB forum is not the "url" value set in config.json

    I can be on mangolassi.it for hours. Then I leave that tab and work in another tab for a while, and then when I click back on the tab for mangolassi.it I will be spammed with connection lost.

    @scottalanmiller

  • 0 Votes
    5 Posts
    1k Views

    @nodemode If you click to select a topic (from the category page itself), you can then shift-click lower down the page to select every topic in between ๐Ÿ˜ƒ

  • 0 Votes
    12 Posts
    6k Views

    Problem solved. It was the nodebb-plugin-cash who caused the problem.

    After deleting this plugin my NodeBB worked again ๐Ÿ™‚