DEV Community

Cover image for Nginx HTTP Basic Authentication(Kimlik Doğrulama) Kurulumu
Fatih ASLAN
Fatih ASLAN

Posted on

2

Nginx HTTP Basic Authentication(Kimlik Doğrulama) Kurulumu

Aşağıdaki paketlerin kurulumunu gerçekleştirin.

Ubuntu;

sudo apt install nginx apache2-utils
~~~{% endraw %}

Redhat/CentOS;{% raw %}
~~~javascript
yum install epel-release nginx httpd-tools
~~~{% endraw %}

Nginx **/etc/nginx/sites-available/sites.conf** altındaki kaynak konfig dosyası **/etc/nginx/sites-enabled/sites.conf** altında linkli olduğunu düşünerek, Yapılandırma şekli aşağıdaki gibi yapılabilir.

İlk önce aşağıdaki komutları yürütün,{% raw %}
~~~javascript
- mkdir /www/sites/indexpage
- mkdir /www/sites/files
- mkdir /www/sites/files/exclude
- echo Welcome to nginx > /www/sites/indexpage/index.html
~~~{% endraw %}

Ardından **sites.conf** aşağıdaki gibi yapılandırın.{% raw %}

~~~javascript
server {                    ###Şifresiz olarak index sayfası gelmesi için yapılan konfigürasyon
        listen 80 default_server;
        server_name "";

    location / {
            root /www/sites/indexpage;
            index index.html index.htm;
        }

    location /files {           ###/www/sites/files içerisine kullanıcı ve şifre ile erişim sağlamak için yapılan konfigürasyon
        satisfy all;    

        root /www/sites/;

        auth_basic "HTTPS Basic Auth Server";
        auth_basic_user_file .htpasswd;
    }

    location /files/exclude {   ###exclude klasörü için şifresiz erişim sağlamak için yapılan konfigürasyon
        alias /www/sites/files/exclude;
    }

}
~~~{% endraw %}

**Basic auth** için kullanıcı ve şifre oluşturma(kullanıcı adı **fatlan**){% raw %}
~~~javascript
sudo htpasswd /etc/nginx/.htpasswd fatlan
~~~{% endraw %}

 Kullanıcıları görmek için(şifreler hashli görüntülenecektir),{% raw %}
~~~javascript
cat /etc/nginx/.htpasswd
~~~{% endraw %}

Son olarak yapılan konfig'lerin geçerli olması için;{% raw %}
~~~javascript
sudo systemctl reload nginx
~~~
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs