nginx rewrite option – last & break

Standard

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite
put simply 「last : ontinue to compare」,「break: stop to compare」.

last

If you access to “/A/foobar.jpg” , you get from “/C/foobar.jpg” .

location /A {
rewrite /A/(.*) /B/$1 last;
}

location /B {
rewrite /B/(.*) /C/$1 last;
}

break

If you access to “/A/foobar.jpg” , you get from “/B/foobar.jpg” .

location /A {
rewrite /A/(.*) /B/$1 break;
}

location /B {
rewrite /B/(.*) /C/$1 last;
}

location match priority in nginx

Standard

https://www.nginx.com/resources/admin-guide/nginx-web-server/
There are two important point only.

POINT1 – forward match & longest match

For example , if it is set as follows in nginx.conf, access to the “/images/foobar.gif” , apply the “location /images/” .

server {
location /images/ {
root /data;
}

location / {
proxy_pass http://www.example.com;
}
}

POINT2 – the priorities of exactly match & regular expression

priority prefix example
1 = (exactly) location = /path
2 ^~ (forward match) location = /image
3 ~ (regular expression & case-sensitive) location ~ /image/
4 ~* (regular expression & case-insensitive) location ~* .(jpg|png)
5 NONE (forward match) location /image

python uwsgi install error – Python.h: No such file or directory

Standard

error – Python.h: No such file or directory

$ sudo pip install uwsgi
    :
[arm-linux-gnueabihf-gcc -pthreadIn file included from plugins/python/python_plugin.c:1:0:
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
 #include <Python.h>
               ^
compilation terminated.
    :
[arm-linux-gnueabihf-gcc -pthread] core/config_py.o
*** uWSGI compiling embedded plugins ***
[arm-linux-gnueabihf-gcc -pthread] plugins/python/python_plugin.o
----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-dQkMew/uwsgi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ACw6M6-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-dQkMew/uwsgi
Storing debug log for failure in /root/.pip/pip.log
$

solution – install python-dev

$ sudo apt-get install python-dev 

 

auth basic in nginx

Standard

http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html

STEP0/2 – install htpasswd command

for centos

# yum install httpd-tools

for debian or raspbian

# apt-get install apache2-utils

STEP1/2 – make password file

$ sudo /usr/bin/htpasswd -c /usr/local/nginx19/conf/auth_basic_passwd end0tknr
New password: 
Re-type new password:

STEP2/2 – edit nginx.conf

You add “auth_basic” & “auth_basic_user_file” , as below.

# vi /usr/local/nginx19/conf/nginx.conf
http {
    :
    server {
        listen       80;
        server_name  raspi.end0tknr.mydns.jp;
        return 302 https://$host$request_uri;
    }

    server {
        :
        auth_basic "MEMBER ONLY";
        auth_basic_user_file "auth_basic_passwd";

        location / {
            root   html;
            index  index.html;
#            auth_basic "off";
        }
    }
}

If the need for auth for each url is different, you add 「auth_basic “off”」 in location delective.