我正在 Windows 10 機器上本地使用 minikube 處理 Kubernetes 部署服務,因此當我公開我的服務(expressjs API)時,我可以通過以下方式訪問它: localhost:3000


我想在網路上公開該服務,以便我可以從另一臺設備(我的手機)測驗 API 來做到這一點我安裝了 Nginx 以設定反向代理將埠 80 上的所有傳入請求轉發到localhost:3000/api 但是當我點擊 localhost 它顯示Nginx 的默認頁面?

這是我的 nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:3000/api/;
}
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
`
uj5u.com熱心網友回復:
這里可能會發生一些事情:
Nginx 配置改變后,沒有執行應用的停止和重新加載;這是加載新配置所必需的,并使用命令執行
nginx -s stop,然后nginx -s reload。意外運行多個實體:如果由于某種原因多次運行該命令
start nginx,則每次都會運行一個行程,并且無法使用該nginx -s stop命令殺死它們;在這種情況下,您需要終止任務管理器上的行程或重新啟動 Windows 系統。請注意,Windows版Nginx 被視為測驗版,它存在一些性能和可操作性問題,如以下檔案 [1] 中所述。
我建議切換到完全支持 Minikube 和 Nginx 的 Linux 系統。您的方案已在 Ubuntu VM 上復制并按預期作業。
[1] http://nginx.org/en/docs/windows.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/347877.html
標籤:nginx Kubernetes nginx-反向代理 迷你酷 nginx配置
