After using THE NSQ message queue, you can view the management interface directly by visiting http://localhost:4171 locally. However, in the production environment, server port 4171 cannot be directly exposed. In this case, you need to configure the Nginx proxy.

However, nsqadmin configuration nginx pit, simple through proxy_pass http://127.0.0.1:4171/ is still unable to display the normal management interface. All kinds of articles searched on the Internet, none of them work. This article documents the correct nginx proxy configuration for NSqadmin.

  1. Generate static files. If the following configuration is performed, the browser url nsqadmin.example.com/nsq displays that various static resources, such as CSS and JS, cannot be found (404). In this case, you need to proxy the static resource directory.

    server {
        listen       80;
        server_name  nsqadmin.example.com;
        auth_basic "NSQAdmin Auth";
        auth_basic_user_file auth-passwd/nsqadmin-htpasswd;
        location /nsq/ {
            proxy_pass http://127.0.0.1:4171/;
      }
    Copy the code

    To generate a static resource file, follow the instructions in the official repository NSQ/NSqadmin at Master · NSqio/NSQ (github.com) :

    # 1. clone repo
    git clone https://github.com/nsqio/nsq.git
    cd nsqadmin
    # 2. install go-bindata
    go get -u github.com/shuLhan/go-bindata
    # 3. install NodeJS 14.x (includes npm)
    # 4. install dependencies
    npm install
    #5. Perform/gulp --series clean watch # or run./gulp --series clean build#6. Perform
    go-bindata --debug --pkg=nsqadmin --prefix=static/build/ static/build/...
    Copy the code

    If this is too much work, you can copy the static folder compiled in the repository, that is, the static folder in the nsqadmin directory.

    The above procedure builds all related static files into the static/build/ directory, which we need to copy to a directory on the server, such as /data/static. Then nginx is configured as follows:

    server {
        listen       80;
        server_name  nsqadmin.example.com;
        auth_basic "NSQAdmin Auth";
        auth_basic_user_file auth-passwd/nsqadmin-htpasswd;
        location /nsq/ {
            proxy_pass http://127.0.0.1:4171/;
        }
        location /static/ {
            alias  /data/static/ 
        }
    }
    Copy the code
  2. The agent/API

Once the nginx configuration is complete, the nsqadmin home page is displayed, but when we click on interaction, we still get an error. If you look at the page request, you will see that NSQadmin is requesting/API routes, and the routes are displayed as 404. We need to proxy/API inside NSQ. Therefore, you need to add the following configuration:

server {
    listen       80;
    server_name  nsqadmin.example.com;
    auth_basic "NSQAdmin Auth"; 
    auth_basic_user_file auth-passwd/nsqadmin-htpasswd;
    location /nsq/ {
        proxy_pass http://127.0.0.1:4171/;
    }
    location /static/ {
        alias  /data/static/ 
    }
    location /api {
        proxy_passhttp://127.0.0.1:4171/nsq$request_uri; }}Copy the code

Finally, restart nginx, visit nsqadmin.example.com/nsq, and enter the user name and password to access the nsqadmin management interface.