簡體   English   中英

Nginx 通過端口 10000 提供 HTTPS 和 Express 應用程序的基本身份驗證?

[英]Nginx to give HTTPS over port 10000 and Basic Auth for Express app?

我有一個 Linux NodeJS/Express 應用程序,它只向http://example.com/secret.txt公開一個文本文件,我希望只能通過 Z0E8433F9A404F1F3213 Auth 端口和基本身份驗證端口訪問。

secret.txt不是文件系統上的文件。 它僅存在於 memory 中。

這一切在 Nginx 中很容易設置,所以問題就變成了:

問題

Nginx 可以通過基本身份驗證通過端口 10000 為我的 NodeJS/Express 應用程序 HTTPS 提供嗎?

我不確定我是否正確理解您的環境,但如果我是,那么非常基本的服務器塊看起來像

server {
    listen 10000 ssl;
    server_name example.com;
    ssl_certificate /path/to/your/certificate;
    ssl_certificate_key /path/to/your/certificate/key;

    location / {
        # how we must serve other requests? assuming we should return 404 not found
        return 404;
        # we can also use special nginx 444 code to close incoming connection immediately
    }
    location = /secret.txt {
        auth_basic "Restricted area"; # whatever you want message
        auth_basic_user_file /path/to/your/passwords/file;
        proxy_pass http://127.0.0.1:<your_nodejs_app_port>;
    }
}

很明顯,node.js 應用程序端口不應該暴露在互聯網上,並且應該只能通過127.0.0.1localhost在本地訪問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM