gpt4 book ai didi

Nginx:如何在以下配置中将每个 http:port 请求重定向到 HTTPS:port?

转载 作者:行者123 更新时间:2023-12-05 01:35:43 27 4
gpt4 key购买 nike

这是我的 nginx.conf,适用于 https。

如果有人输入 HTTP://dev.local.org:3002,我该如何重定向到 HTTPS://dev.local.org:3002?

这个 nginx 在 docker-compose 容器中。

worker_processes 1;
events {
worker_connections 1024;
}

#set $my_server_name _ #TODO global variable does not work?

http {
#DOCKER DNS - using this to resolve docker-compose hosts like 'appsearch', 'kibana' etc
resolver 127.0.0.11 ipv6=off;

#include mime.types;
default_type application/octet-stream;
#TO read external configuration
include sites-enabled/*.conf;


server { #DEFAULT SERVER
listen 443 ssl; # Security change
server_name _;

include common.conf;
include /etc/nginx/ssl.conf;

location / {
root html;
index index.html index.htm;
include common_location.conf;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# location /appsearch { #TODO this /appsearch did not forward. find how to do it.
# rewrite ^/appsearch(.*) /$1 break;
# resolver 127.0.0.11 valid=30s ;
# set $backend http://appsearch:3002;
# proxy_pass $backend; # Use variable To avoid upstream host not found error.
# }

}#server80

server {
listen 9200 ssl;
server_name _;

include common.conf;
include /etc/nginx/ssl.conf;

location / {
set $backend http://elasticsearch:9200;
proxy_pass $backend; # Use variable To avoid upstream host not found error.
include common_location.conf;
}
}#server

server {
listen 3002 ssl;
#server_name dev.local.org; #TODO yuck, bad to add server name!
server_name _;
include common.conf;
include /etc/nginx/ssl.conf;

location / {
set $backend http://appsearch:3002;
proxy_pass $backend; # Use variable To avoid upstream host not found error.
include common_location.conf;
}
}#server

server {
listen 5601;
server_name _;
include common.conf;
include /etc/nginx/ssl.conf;

location / {
set $backend http://kibana:5601;
proxy_pass $backend; # Use variable To avoid upstream host not found error.
include common_location.conf;
}
}#server
}

最佳答案

使用 497 HTTP 错误重定向:(来源:https://meabed.com/http-497-status-code/)

在您的 conf 中,您将添加如下内容:

 
listen 1234 ssl;

server_name your.site.tld;

ssl on;

error_page 497 https://$host:1234$request_uri;

}```

关于Nginx:如何在以下配置中将每个 http:port 请求重定向到 HTTPS:port?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62747366/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com