D
D
Duke_Nukem1472018-07-17 10:44:08
Nginx
Duke_Nukem147, 2018-07-17 10:44:08

Nginx how to make htaccess for query string?

Hello, I have a page in redmine that should require a password.
For example, this works for me

location /projects/wwe/dmsf
{
        auth_basic "Test4";
        auth_basic_user_file /etc/nginx/legalinfopass;
        alias /usr/share/redmine/public;
        try_files $uri @fcgi;
}

And what I really need is not working
location /projects/wwe/dmsf?folder_id=351
{
        auth_basic "Test4";
        auth_basic_user_file /etc/nginx/legalinfopass;
        alias /usr/share/redmine/public;
        try_files $uri @fcgi;
}

All my redmine.conf config
upstream redmine_default
{
    #server localhost:3000;
    server unix:/tmp/redmine.socket;
}

server
{
    include listen.conf;
    include listen_ssl.conf;

        ssl_certificate_key /etc/letsencrypt/live/redmine.wwe.com/privkey.pem;
        ssl_certificate /etc/letsencrypt/live/redmine.wwe.com/fullchain.pem;

        server_name www.redmine.wwe.com redmine.wwe.com;

# letsencrypt
        location ~ ^/\.well-known/acme-challenge
        {
                auth_basic off; root /home/www/acme;
        }

    location /
    {
        rewrite ^ https://redmine.wwe.org$request_uri? permanent;
    }
}

server
{
    listen 192.168.110.24;
    server_name redmine.wwe.org www.redmine.wwe.org;

    # letsencrypt
    location ~ ^/\.well-known/acme-challenge
    {
        auth_basic off;
        root /home/www/acme;
    }

    location /
    {
        rewrite ^ https://redmine.wwe.org$request_uri? permanent;
    }
}

server
{
    listen 192.168.110.24:443 ssl http2;

    client_max_body_size 250M;

    server_name redmine.wwe.org;

    ssl_certificate_key /etc/letsencrypt/live/www.redmine.wwe.org/privkey.pem;
    ssl_certificate /etc/letsencrypt/live/www.redmine.wwe.org/fullchain.pem;


# letsencrypt
    location ~ ^/\.well-known/acme-challenge
    {
        auth_basic off; root /home/www/acme;
    }

    location /projects/wwe/wiki/PHP_programmers
    {
        auth_basic "Test";
        auth_basic_user_file /etc/nginx/wikipass;
        alias /usr/share/redmine/public;
        try_files $uri @fcgi;
    }

    location /projects/wwe/wiki/Vacancy_interviews
    {
        auth_basic "Test";
        auth_basic_user_file /etc/nginx/wikipass;
        alias /usr/share/redmine/public;
        try_files $uri @fcgi;
    }

    location /projects/wwe/wiki/Hidden_for_creds
    {
        auth_basic "Test2";
        auth_basic_user_file /etc/nginx/credpass;
        alias /usr/share/redmine/public;
        try_files $uri @fcgi;
    }

    location /projects/wwe/wiki/Management
    {
        auth_basic "Test3";
        auth_basic_user_file /etc/nginx/managementpass;
        alias /usr/share/redmine/public;
        try_files $uri @fcgi;
    }

    location /projects/wwe/dmsf?folder_id=351
    {
                auth_basic "Test4";
                auth_basic_user_file /etc/nginx/legalinfopass;
                alias /usr/share/redmine/public;
                try_files $uri @fcgi;
    }

    location /files
    {
        auth_basic off;
        internal;
        root /usr/share/redmine;
    }

    location /public
    {
        auth_basic off;
        internal;
        root /usr/share/redmine;
    }

    location /tmp2
    {
        auth_basic off;
        internal;
        root /usr/share/redmine;
    }


    location /
    {
        auth_basic off;
        alias /usr/share/redmine/public;
        try_files $uri @fcgi;
    }

    location @fcgi
    {
        auth_basic off;

        ##proxy_set_header X-Sendfile-Type X-Accel-Redirect;
        ##proxy_set_header X-Accel-Mapping /usr/share/redmine/=/;

        ##proxy_pass http://redmine2_default;
        include uwsgi_params;
        uwsgi_pass redmine_default;
        uwsgi_modifier1 7;
    }
}

Do not tell me how to be here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danila Vershinin, 2018-07-17
@Duke_Nukem147

Using `if` inside `location` as in the previous solution is not recommended .
Correct like this:

http {
  ...
  map $arg_folder_id $loc_auth {
    default "off";
    351 "Test4";
  }

  server {
    ...	
    location /projects/wwe/dmsf {
      ...
      auth_basic $loc_auth; 
      ...
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question