我在Ubuntu 20.04上运行Nginx,并试图创建一个NGINX配置,以将特定http请求的域更改为不同的域。如果主机上的任何https请求都是针对域www.example.com发出login.windows.net,我希望将该域交换为使用login.microsoftonline.com。
例如,如果请求如下所示:
https://login.windows.net/fe3f3811-3e28-4a4e-a122-3e1135c01bf2/v2.0/.well-known/openid-configuration
我想把它改写成
https://login.microsoftonline.com/fe3f3811-3e28-4a4e-a122-3e1135c01bf2/v2.0/.well-known/openid-configuration的
我的Nginx配置如下所示:
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
server {
# The listen directive serves content based on the port defined
listen 80;
listen 443 ssl http2 default_server;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
ssl on;
access_log /var/log/nginx/reverse-access.log;
error_log /var/log/nginx/reverse-error.log;
location /fe3f3811-3e28-4a4e-a122-3e1135c01bf2 {
rewrite ^/fe3f3811-3e28-4a4e-a122-3e1135c01bf2(.*)$ https://login.microsoftonline.com/$1 redirect;
}
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
字符串
但是,每当我使用此配置加载并重新启动nginx并发出curl请求时:
curl -L https://login.windows.net/fe3f3811-3e28-4a4e-a122-3e1135c01bf2/v2.0/.well-known/openid-configuration
它不会取代组态。
我还尝试过进行代理通道配置:
location /fe3f3811-3e28-4a4e-a122-3e1135c01bf/v2.0/.well-known/openid-configuration {
proxy_pass_request_headers on;
proxy_pass https://login.microsoftonline.com/fe3f3811-3e28-4a4e-a122-3e1135c01bf/v2.0/.well-known/openid-configuration;
}
型
还是不管用。如何简单地替换https调用的域??
1条答案
按热度按时间ewm0tg9j1#
也许可以尝试使用以下配置为您的域添加一个服务器块:
字符串