添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I rpm installed nginx 1.12 on a redhat 7.5 server and It also has LUA 5.1.4 I downloaded lua-nginx-module-0.10.13 tar ball and put it under /etc/nginx/modules, but I am not able to run nginx with LUA auth file.

I also have openresty under /opt/openresty/ ..

http://openresty.org/en/installation.html I followed the "make" method here.

Unfortunately this server doesnt have access to the internet so I cant install stuff from git which slows this down considerably. I am not sure how to add the module here. Any comments would be helpful.

This is what my nginx config looks like ..

server
    listen 80;
    access_log  /opt/elk/logs/nginx/access.log  main;
    #auth_basic "admin";
    #auth_basic_user_file "/etc/nginx/passwd";
    client_max_body_size 100M;
    location /
        proxy_pass http://127.0.0.1:9200;
        keepalive_timeout 300s;
        #auth_basic on;
        auth_basic "admin";
        auth_basic_user_file "/etc/nginx/passwd";
        access_by_lua_file '/etc/nginx/authorized.lua';
    error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html
        root   /usr/share/nginx/html;

The lua_access_file is causing an error

nginx: [emerg] unknown directive "access_by_lua_file" Is there some "include" I need to define in the config to get rid of this ?

Thanks.

I am breaking down your problem into the small task, as per question and my understanding.

1) The error clearly says that you have not install Lua-nginx-module properly.

Lua-nginx-module documentation

2) The server does not have access to the internet so cannot download from git.

  • Assuming you are doing ssh into your machine from windows. So, please check below link to copy the files from windows to Linux.

    Installing/Accessing via WinSCP

    how-to-copy-files-from-one-machine-to-another-using-ssh

  • this step will get all the necessary files on your server.
  • 3) Steps to install nginx with lua-nginx-module.

  • lua nginx module compatibility check.

     Nginx Compatibility
         The latest version of this module is compatible with the following versions of Nginx:
         1.13.x (last tested: 1.13.6)
         1.12.x
         1.11.x (last tested: 1.11.2)
         1.10.x
         1.9.x (last tested: 1.9.15)
         1.8.x
         1.7.x (last tested: 1.7.10)
         1.6.x
         Nginx cores older than 1.6.0 (exclusive) are not supported.
    

    referance document for nginx compatibility

  • Prerequisites

    **- Centos/RHEL**[**In case if internet is working in your server**].
     yum install -y wget unzip gcc make openssl-devel pcre-devel zlib-devel 
    

    - Downloading .rpm package manually and installing.

  • Search the prerequisites from the RPM resource site

  • RPM resource site
  • Copy the file in your Linux box

  • Please refer above point (2)"The server does not have access to the internet so cannot download from git".
  • Install with the following command.

      rpm -i rpm-package-name
    

    Install-rpm-file-on-linux

    - Tarball installation for prerequisites.

     - [Installing gcc from source code ][6]         Similarly,you can look for
              other prerequistes.
    
  • Downloading the source

     $ rm -fr /tmp/nginx-build  
     $ mkdir /tmp/nginx-build
     $ cd /tmp/nginx-build
     $ wget http://nginx.org/download/nginx-1.13.0.tar.gz
     $ wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
     $ wget -O nginx_devel_kit.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
     $ wget -O nginx_lua_module.tar.gz https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
    
  • Extracting

      $ tar xvf LuaJIT-2.0.4.tar.gz
      $ tar xvf nginx-1.11.10.tar.gz
      $ tar xvf nginx_devel_kit.tar.gz
      $ tar xvf nginx_lua_module.tar.gz
    
  • Building LuaJIT

    To build Nginx with LuaJIT, we need to build LuaJIT first. This is as simple as a make command

        $ cd /tmp/nginx-build/LuaJIT-2.0.4
        $ make install
         ==== Building LuaJIT 2.0.4 ====
         make -C src
         make[1]: Entering directory `/tmp/nginx/LuaJIT-2.0.4/src'
         ln -sf luajit-2.0.4 /usr/local/bin/luajit
         ==== Successfully installed LuaJIT 2.0.4 to /usr/local ====
    
  • Building Nginx

         $ cd /tmp/nginx-build/nginx-1.11.10
         $ LUAJIT_LIB=/usr/local/lib LUAJIT_INC=/usr/local/include/luajit-2.0 \
         ./configure \
         --user=nobody                          \
         --group=nobody                         \
         --prefix=/etc/nginx                   \
         --sbin-path=/usr/sbin/nginx           \
         --conf-path=/etc/nginx/nginx.conf     \
         --pid-path=/var/run/nginx.pid         \
         --lock-path=/var/run/nginx.lock       \
         --error-log-path=/var/log/nginx/error.log \
         --http-log-path=/var/log/nginx/access.log \
         --with-http_gzip_static_module        \
         --with-http_stub_status_module        \
         --with-http_ssl_module                \
         --with-pcre                           \
         --with-file-aio                       \
         --with-http_realip_module             \
         --without-http_scgi_module            \
         --without-http_uwsgi_module           \
         --without-http_fastcgi_module ${NGINX_DEBUG:+--debug} \
         --with-cc-opt=-O2 --with-ld-opt='-Wl,-rpath,/usr/local/lib' \
         --add-module=/tmp/nginx/ngx_devel_kit-0.3.0 \
         --add-module=/tmp/nginx/lua-nginx-module-0.10.8
         $ make install
    
  • Syntanx Check

      $ nginx -t
         nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
         nginx: configuration file /etc/nginx/nginx.conf test is successful
    
  • Nginx Lua Testing

    *As per you nginx file.

      location /
     proxy_pass http://127.0.0.1:9200;
     keepalive_timeout 300s;
     #auth_basic on;
     auth_basic "admin";
     auth_basic_user_file "/etc/nginx/passwd";
     access_by_lua_file '/etc/nginx/authorized.lua'; }
    
  • Reload / restart nginx

         systemctl nginx restart
         systemctl nginx reload.
    

    how-to-reload-nginx-systemctl-or-nginx-s

    Thank you, I was following these steps when I had a run at it the first time, I was able to gather the relevant files and start to compile but I was having issues with the command on "building nginx" previously. I will give this another try. – ScipioAfricanus Oct 30, 2018 at 15:00 @ScipioAfricanus Yes, I totally understand building "Lua-nginx-module" is bit tricky and It does not provide expected results sometimes. I too faced many issues and drafted this after several attempts. It worked for me, give it a try and Do let us know, how it goes for you. – Akshay barahate Oct 31, 2018 at 6:23 @Akshaybarahate, I faced error for make install /home/nginx-build/lua-nginx-module-0.10.8/src/ngx_http_lua_headers.c:227:15: error: incompatible types when assigning to type ‘ngx_buf_t * {aka struct ngx_buf_s *}’ from type ‘ngx_chain_t {aka struct ngx_chain_s}’ b = hc->busy[i]; ^ objs/Makefile:1446: recipe for target 'objs/addon/src/ngx_http_lua_headers.o' failed make[1]: *** [objs/addon/src/ngx_http_lua_headers.o] Error 1 make[1]: Leaving directory '/home/nginx-build/nginx-1.19.3' Makefile:11: recipe for target 'install' failed make: *** [install] Error 2 – Techiescorner Jun 9, 2021 at 7:56

    Now in most Operating Systems (e.g. Ubuntu, etc) Lua support for Nginx can be enabled by installing the libnginx-mod-http-lua package. e.g:

    sudo apt install libnginx-mod-http-lua
    

    This package includes the dynamic library and the corresponding load_module directive in /usr/share/nginx/modules-available/mod-http-lua.conf which is usually enabled when the package is installed (by softlinking it into the /etc/nginx/modules-enabled/ directory).

    In case you are running nginx with docker you can just follow the instructions on the docker-nginx github repository.

    In your nginx-conf make sure to also load the module by adding

    load_module modules/ndk_http_module.so;
    load_module modules/ngx_http_lua_module.so;
    load_module modules/ngx_stream_lua_module.so;
    

    The package name may vary, the above file name is derived from an ubuntu 18.04 installation from package. (Usually you find your modules in /usr/share/nginx/modules)

    Note: If you compiled nginx from source (which seems to be the recommended way to get lua running), pathes and filenames can vary.

    Happy codin'.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •