install camo for nodebb-plugin-iframely

Technical Support
  • Hello,

    I try to install on my server camo (github) which is very usefull for iframely for example.
    As i am starting with node app, i am a little lost.

    The steps i did:

    • Create a domain: camo.domain.com and configure DNS > ok

    • Into a folder ~/nginx/html/camo.domain.com > ok

        git clone https://github.com/atmos/camo.git
        cd camo
        npm install
    
    • Configure Camo?? > KO
      In the folder, there is a file server.js but it doesn't seem there is a way to configure the variables.

    • Create a host and enabled it > ok

        upstream camo.domain.com {
                ip_hash;
                server localhost:8081;
                keepalive 8;
        }
        server {
    
                server_name camo.domain.com;
                client_max_body_size 20m;
    
                listen 80;
                listen [::]:80;
                listen 443 ssl;
    
                # config ssl
                ssl_certificate /etc/letsencrypt/live/camo.domain.com/fullchain.pem;
                ssl_certificate_key /etc/letsencrypt/live/camo.domain.com/privkey.pem;
                fastcgi_param HTTPS on;
                keepalive_timeout    70;
                ssl_session_cache    shared:SSL:10m;
                ssl_session_timeout  10m;
    
                # add Strict-Transport-Security to prevent man in the middle attacks
                add_header Strict-Transport-Security "max-age=31536000";
    
                # Logs
                access_log /var/log/camo.access_log;
                error_log /var/log/camo.error_log;
    
                # redirect HTTP to HTTPS
                if ($scheme = http) {
                        return 301 https://$server_name$request_uri;
                }
    
                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 https://camo.domain.com/;
                        proxy_redirect off;
    
                        # Socket.IO Support
                        proxy_http_version 1.1;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
                }
    
                # Exclude from the logs to avoid bloating when it's not available
                include drop.conf;
    
        }
    
    • then i suppose i have to do node server.js

    Because i don't achieve the configuration, logically when i go to https://camo.domain.com/, i get an 502 error bad getaway.

    How can i configure efficiently Camo?
    And do i get the right way to finish well the install?
    Then can i add forever server.js ?

    Thank you in advance for any help.
    jB

  • Hey @j-b-o,

    camo is being configured by environment variables which is why I usually run it in docker. To fix your case you should be able to start your server by using:

    PORT=8081 CAMO_KEY="<your camo key>" node server.js
    

    (You could actually not add the PORT env, as 8081 is the default, but I added it to show you better how to add variables.)

    Other variables you could add are:

    • PORT: The port number Camo should listen on. (default: 8081)
    • CAMO_HEADER_VIA: The string for Camo to include in the Via and User-Agent headers it sends in requests to origin servers. (default: Camo Asset Proxy <version>)
    • CAMO_KEY: The shared key used to generate the HMAC digest.
    • CAMO_LENGTH_LIMIT: The maximum Content-Length Camo will proxy. (default: 5242880)
    • CAMO_LOGGING_ENABLED: The logging level used for reporting debug or error information. Options are debug and disabled. (default: disabled)
    • CAMO_MAX_REDIRECTS: The maximum number of redirects Camo will follow while fetching an image. (default: 4)
    • CAMO_SOCKET_TIMEOUT: The maximum number of seconds Camo will wait before giving up on fetching an image. (default: 10)
    • CAMO_TIMING_ALLOW_ORIGIN: The string for Camo to include in the Timing-Allow-Origin header it sends in responses to clients. The header is omitted if this environment variable is not set. (default: not set)
    • CAMO_HOSTNAME: The Camo-Host header value that Camo will send. (default: unknown)
    • CAMO_KEEP_ALIVE: Whether or not to enable keep-alive session. (default: false)

    I would also recommend installing screen and forever, on Debian you would do this by executing:

    apt-get install screen && npm i -g forever
    

    and then starting your app with:

    screen -S camo sudo PORT=8081 CAMO_KEY="<your camo key>" forever server.js
    

    This runs camo in a screen you can exit by using CTRL+A+D while still letting it run in the background and preserving any error logs. forever keeps care of restarting it in case it crashes. Test if your server.js starts by manually using node though before you use them both, otherwise you'll create a process crashing and restarting really fast.

  • @lenovouser thank you very much for the answer

    So i have generate a key:
    pwgen -sB 64

    Then run:
    PORT=8081 CAMO_KEY="my_key" node server.js

    In the terminal i get:

    SSL-Proxy running on 8081 with pid:11313 version:2.3.0.
    

    So it seems to work, doesn't it?

    Unfortunatly when i try the url for example:
    https://camo.domain.com/my_key?url=http://puppaleslie.free.fr/favicon.ico

    I always get an error 502 bad getaway
    I guest i have a problem with my host config.

    Still investigating, thank you for the help.
    jB

  • @j.b.-o., yes. Replacing

    upstream camo.domain.com { -> upstream camo {

    and

    proxy_pass https://camo.domain.com/; -> proxy_pass http://camo;

    should fix it.

  • @lenovouser thank you

    To understand, that the upstream configuration change?

    It seems to perfectly fix the problem. Unfortunatly when i try to load these image:

    https://camo.domain.com/my_key?url=https://www.howtoforge.com/images/linux_screen/2.png

    I get not found

    https://camo.domain.com/my_key/https://www.howtoforge.com/images/linux_screen/2.png

    I get this image cannot be display because it contains errors

    Idem with this file: http://puppaleslie.free.fr/favicon.ico

    Could it be an issue? In this case i will open a ticket on github.

    About screen and forever, to understand well:

    • forever is the reboot the process at a crash
    • screen is to run multi terminal "session", so it allow to let a terminal running with the camo app

    About screen, could it be done the same with passing the option CAMO_KEEP_ALIVE to true on running?

    Thanks,
    jB

  • @j.b.-o. sorry for the late reply! @yariplus and me just released

    which should make this whole process a lot more easier and automatic. You can find the explanation post here.


Suggested Topics


  • 0 Votes
    4 Posts
    524 Views
  • nodebb version

    Technical Support
    0 Votes
    4 Posts
    277 Views
  • 0 Votes
    2 Posts
    1177 Views
  • 0 Votes
    13 Posts
    3367 Views
  • 0 Votes
    14 Posts
    7781 Views