Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] install njs scripting language #449

Closed
1 task done
luisalrp opened this issue Jan 22, 2024 · 5 comments
Closed
1 task done

[FEAT] install njs scripting language #449

luisalrp opened this issue Jan 22, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@luisalrp
Copy link

Is this a new feature request?

  • I have searched the existing issues

Wanted change

I would like Nginx njs scripting language installed to perform additional actions not available on SWAG.

Reason for change

nsj would enable new capabilities, like checking apikey validity on nginx before a request reaches an upstream server, manipulating response headers or writing flexible asynchronous content handlers and filters

Proposed code change

I don't know the best approach. Maybe a dockermod would be better option because some users would not like to have njs by default for security concerns.

Here is the documentation.

@luisalrp luisalrp added the enhancement New feature or request label Jan 22, 2024
Copy link

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

@Roxedus
Copy link
Member

Roxedus commented Jan 22, 2024

Have you confirmed it is not present?

$ docker exec -it swag nginx -V 2>&1 | tr ' ' '\n' | grep njs
--add-dynamic-module=/home/buildozer/aports/main/nginx/src/njs-0.7.11/nginx

@luisalrp
Copy link
Author

luisalrp commented Jan 22, 2024

Hello Roxedus

Thanks for answering. When I run the docker exec instruction I got the same line, but not sure what can I do from it. I mean, if I try to go there, there is no folder or file and checking the njs conf examples neither the /etc/nginx/njs is present.

Here is an example of a conf file :

load_module modules/ngx_http_js_module.so;

events {  }

http {
    js_path "/etc/nginx/njs/";

    js_import utils.js;
    js_import main from http/hello.js;

    server {
        listen 80;

        location = /version {
            js_content utils.version;
        }

        location / {
            js_content main.hello;
        }

    }
}

@Roxedus
Copy link
Member

Roxedus commented Jan 22, 2024

You need the nginx-mod-http-js OS package, you can install it with the universal package mod.

You then have the needed directives present, like js_path.

Then you just have to configure nginx like normal, with the additional directives.

My quick test was something like adding

    js_path "/config/nginx/njs/";
    js_import main from hello.js;

to the existing http block, where I created the njs directory, and put the hello.js file from the example repo you linked.
Then add the location, like you would with a proxy_pass, ie

    location = /hello.html {
        js_content main.hello;
    }

to a server block.

@Roxedus Roxedus closed this as completed Jan 22, 2024
@LinuxServer-CI LinuxServer-CI moved this from Issues to Done in Issue & PR Tracker Jan 22, 2024
@luisalrp
Copy link
Author

Thank you so much Roxedus!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

2 participants