Nginx

From Wasya Wiki
Jump to: navigation, search

Install

From source: https://nginx.org/en/download.html

 apt-get install libpcre3 libpcre3-dev
 ./configure --with-http_dav_module  
 make
 make install


Use

basic auth

From: https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/

 sudo htpasswd -c /etc/apache2/.htpasswd user1
 sudo htpasswd    /etc/apache2/.htpasswd user2
 location /api {
   auth_basic           "Administrator’s Area";
   auth_basic_user_file /etc/apache2/.htpasswd; 
 }

nice headers config

    location / {
        proxy_pass http://movim;
        # force timeouts if the backend dies
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

        # set headers
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $remote_addr;
        proxy_set_header X-Forwarded-Port $server_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Server-Select $scheme;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Url-Scheme: $scheme;
        proxy_set_header Host $host;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Upgrade $http_upgrade;
        proxy_http_version 1.1;

        # by default, do not forward anything
        proxy_redirect off;
    }

performance

From: https://medium.com/@anirudhdey/maximizing-concurrency-in-nginx-tips-and-trick-df23c10cda71

restart

 sudo pkill -f nginx & wait $!
 sudo systemctl start nginx