nginx - windows上的nginx不重定向?
问题描述
我正在我的 Windows 10 机器上本地使用 minikube 开发 Kubernetes 部署服务,所以当我公开我的 expressjs API 服务时,我可以通过以下方式访问它:localhost:3000
我想在网络上公开该服务,以便可以从另一台设备(我的手机)测试localhost:3000/api
API 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;
# }
#}
}
`
解决方案
这里可能会发生一些事情:
Nginx 配置更改后,没有执行应用的停止和重新加载;这是加载新配置所必需的,并使用命令执行
nginx -s stop
,然后nginx -s reload
。意外运行多个实例:如果由于某种原因该命令
start nginx
多次运行,则每次都会运行一个进程,并且无法用该nginx -s stop
命令杀死它们;在这种情况下,您将需要终止任务管理器上的进程或重新启动 Windows 系统。请注意,Nginx for Windows 被视为beta版本,它存在一些性能和可操作性问题,如以下文档 [1] 中所述。
我建议切换到完全支持 Minikube 和 Nginx 的 Linux 系统。您的方案已在 Ubuntu VM 上复制,并且按预期工作。
推荐阅读
- firebase - 使用管理员 SDK 进行 Firebase 身份验证?
- components - 如何将 IEventBroker 注入 e4 OSGI 服务组件
- pine-script - 将不同版本的 pine 脚本相互转换的问题
- jsonassert - 如果生成的有效负载具有附加数组值,则 JSONAssert.assertequals 比较两个 json 失败
- go - 函数名没有正确解析
- python - 如何为x行随机分配0或1取决于excel中的y列值
- r - 分别使用 r 中的 sub 将第一个和第二个“-”替换为“_”和“:”
- javascript - 嵌入 iframe 的网站能否读取父网站 cookie?
- python - 替换每个组的值
- kubernetes - 在 K8s 的 Prometheus 服务中添加额外的 ScrapeConfigs