Installing NodeBB in a subfolder of another site



  • @julian

    I'm not an Arab or Asian and I didn't notice it. What's my excuse?



  • @baris, @julian, @psychobunny, I'm still on this.

    If I modify the code given here for the subfolder installation to look like this:

    upstream nodejs {
        server 192.168.1.4:4567;
    }
    
    server {
        listen 80;
    
        server_name 192.168.1.4:4567;
        root /var/www/forum;
    
        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://192.168.1.4:4567;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    I get a 403 Forbidden error message when I attempt to access http://ip-address/forum.

    And if I replace server_name 192.168.1.4:4567; with server_name 192.168.1.4/forum;. nginx -t reports"

    nginx: [warn] server name "127.0.0.1/forum" has suspicious symbols in /etc/nginx/sites-enabled/default:91
    

    Note that NodeBB (nodejs) is listening on the default port, even though I didn't want it to.

    Any suggestions?


  • Admin

    NodeBB has to listen on a port. It could listen on a UNIX socket, but that's outside of the scope of this question (and is pretty pointless, anyway).

    Given your nginx config, please make the following changes:

    • Remove the upstream portion, as you don't seem to be referencing it anymore
    • Remove the root directive, it is not required
    • server_name should be 192.168.1.4, no port

    nginx -t should work then, and you can restart it and try again.

    nginx: [warn] server name "127.0.0.1/forum" has suspicious symbols in /etc/nginx/sites-enabled/default:91

    If you still get this error, take a look at what's on line 91 of default..!



  • @julian

    I'm getting warmer. Here's what I did:

    I just added the code below into the default server block, that is, no separate server block for NodeBB.

    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://192.168.1.4:4567;
            proxy_redirect off;
        }
    

    Navigated to http://ip-address/forum and got the default page, minus the default categories. And clicking on any of the buttons returns nothing. No error messages in the log files.

    I'll recircle back to the previous attempt, but what do you make of this?

    Here's a screenshot:

    NodeBBerror1.jpg


  • Admin

    What shows up in the console tab of the chrome inspector? This will help @baris debug, if necessary



  • @julian

    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 
    

    That's the type of messages on clicking on any link.

    In Nginx's access.log, I get lines like:

    "GET /forum/api/config HTTP/1.1" 200 265 "http://192.168.1.4/forum/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36"
    

    Nothing in Nginx's error.log.

    Btw, clicking on the Unread link loads the default Nginx page.



  • Ok, @baris, @julian, @psychobunny, I think I've gone the whole nine yards on this. The problem is most likely that NodeBB is not at the state where it can be installed and work correctly in a subfolder. The best I've been able to get, is a blank home page with header links that don't work.

    I'll just keep adding content to the live site and hope that somebody takes a shot at fixing it before it goes live.

    If you guys want to use me as a test case, go right ahead!



  • @julian, @baris

    Is this something that's doable with NodeBB or should I opt for a subdomain installation?


  • Admin

    The last time I tried subfolder installation it was working fine, but I never tried it with nginx proxying. So I suggest you take out all the nginx proxying first and try it with http://domain.com:4567/forum if that is working then figure out proxying.



  • @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

    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?

  • Admin

    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.


 

| |