
我希望我的 Flask 應用程式最終成為一個 api,並在 Windows 伺服器上運行它。我在 google 網域上擁有一個網域,我使用將作為伺服器運行的電腦的 IP 位址新增了 api.(mydomain) 的 DNS。我想讓 api 為 ssl 和 https,並且一直在使用 waitress -> nginx -> win-acme
這是我的目錄: C:\Users\Wreck\Documents\Flask\acme-challenge ,在這個資料夾中,我只用純文字建立了一個 test.txt 。
在 Flask 資料夾中,我有一個 Flask 應用程序,目前僅列印 hello world。
我的第一步是啟動女服務生:
(venv) C:\Users\Wreck\Documents\Flask>waitress-serve --listen=*:5000 flaskappv1:app
INFO:waitress:Serving on http://[::]:5000
INFO:waitress:Serving on http://0.0.0.0:5000
你好世界!顯示在本機上。
然後我設定了 nginx,經過幾個小時的測試,我仍然完全不明白為什麼從 acme-challenge 返回文字檔案仍然會產生錯誤。這是我的程式碼:
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
server {
listen 80;
server_name api.rootmusic.app;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ^~ /.well-known/acme-challenge/ {
root C:/Users/Wreck/Documents/Flask/acme-challenge/;
allow all;
default_type "text/plain";
try_files $uri =404;
}
}
}
這是我的輸出:
C:\WINDOWS\system32>curl http://api.rootmusic.app/.well-known/acme-challenge/test.txt
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
C:\WINDOWS\system32>curl http://api.rootmusic.app/
Hello World!
我已經關閉了Windows Defender。我已從伺服器電腦的 IP 連接埠 80 和 5000 進行連接埠轉送。
我認為這可能與我的讀取和查看權限有關,但在任務管理器中,nginx 運行了 Wreck,這就是我,我很確定是管理員用戶,並且我檢查了整個文件結構的讀寫權限。
如果這有幫助,這是我嘗試使用 win-acme 取得 api.(domain) 的 HTTPS 時收到的錯誤
Plugin Manual generated source api.rootmusic.app with 1 identifiers
Plugin Single created 1 order
Cached order has status invalid, discarding
[api.rootmusic.app] Authorizing...
[api.rootmusic.app] Authorizing using http-01 validation (SelfHosting)
[api.rootmusic.app] Authorization result: invalid
[api.rootmusic.app] {"type":"urn:ietf:params:acme:error:unauthorized","detail":"(my ip): Invalid response from http://api.rootmusic.app/.well-known/acme-challenge/uQdTJeSYMKLUy9_7dIgEzLZQUay11eYUxvKNcxNPPv4: 404","status":403,"instance":null}
[api.rootmusic.app] Deactivating pending authorization
正如您可能已經猜到的,我對系統管理還很陌生。但感謝您閱讀這篇文章。如果您對切換程式有任何建議或有任何更輕鬆的方法,請告訴我,因為我完全陷入困境。我一開始使用的是IIC,但後來改用了nginx,因為我無法弄清楚。
但是,是的,為什麼 nginx 無法讀取 acme-challenge 位置中的檔案?我認為這也是阻止 win-acme 的原因。