我使用 Nginx 作为反向代理。
这些标头有什么区别:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
Run Code Online (Sandbox Code Playgroud)
在一些文档/教程中,我看到两者都被使用,而在其他文档/教程中,只有第一个。
它们看起来很相似,所以我想了解它们有何不同以及我是否需要同时使用两者。
我在标准反向代理场景中使用 nginx,将所有请求传递/auth到另一台主机,但是我正在尝试使用非标准端口。
我的最终目标是将X-Forwarded-Port标头设置为请求进入的端口。
这是我在 nginx.conf 中的位置块:
Run Code Online (Sandbox Code Playgroud)location /auth/ { proxy_pass http://otherhost:8090; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port <VAR>; }
这个 nginx 运行在一个 docker 容器中,该容器被配置为将请求从 8085 转发到容器中的 80,这样 nginx 进程就可以监听 80:
0.0.0.0:8085->80/tcp
当我点击网址时:
我正确重定向到http://otherhost:8090,但X-Forwarded-Port标题丢失或错误。
在<VAR>原始块中,我尝试了以下操作:
$server_port - 这是 nginx 正在侦听的端口 (80),而不是请求端口。
$pass_port - 在我的设置中似乎为空,因此 nginx 删除了标头。
$http_port - 这是每个请求的随机端口。
$remote_port - 这是每个请求的随机端口。
我可以在部署时将我的配置更改为硬编码到传入请求的已知端口,但理想情况下,我将能够更改前端端口,而无需对 nginx 配置进行任何更改。
我已经搜索了 …
reverse-proxy nginx docker x-forwarded-for nginx-reverse-proxy
我正在尝试按照教程Nginx 和 Let's Encrypt with Docker in Less Than 5 Minutes来使用 docker + nginx 设置一个 Django 项目。
问题是当我运行脚本 init-letsencrypt.sh 时,我最终遇到了失败的挑战。
这是我的脚本的内容:
#!/bin/bash
if ! [ -x "$(command -v docker-compose)" ]; then
echo 'Error: docker-compose is not installed.' >&2
exit 1
fi
domains=(xxxx.yyyy.net www.xxxx.yyyy.net)
rsa_key_size=4096
data_path="./data/certbot"
email="myemail@example.com" # Adding a valid address is strongly recommended
staging=1 # Set to 1 if you're testing your setup to avoid hitting request limits
if [ -d "$data_path" ]; then
read -p "Existing data …Run Code Online (Sandbox Code Playgroud) 我想使用 nginx 进行速率限制和缓存。
nginx 以什么顺序应用它们?换句话说,它是仅限制对上游服务器的请求还是所有请求(包括缓存 HIT)?
这个顺序怎么改?我认为它可以通过有两个server上下文来改变。因此,例如,在一个server执行缓存。它有第二个server上下文作为上游。第二个限制对“真实”上游的请求。但这可能不是最有效的方式......
我目前正在尝试为两个Angular应用创建反向代理。我希望都可以通过启用SSL的docker主机的443端口访问应用程序(例如https://192.168.xx/app1和https://192.168.xx/app2),以便用户没有输入每个应用程序的端口号。
我的设置是,应用程序的每个部分都在其自己的Docker容器中运行:-容器1:Angular App 1(端口80暴露在端口8080上的主机上)-容器2:Angular App 2(端口80暴露在端口Port上的主机上) 8081)-容器3:反向代理(端口443暴露)
Angular应用程序和反向代理都在nginx上运行。这些应用程序的构建如下:ng build --prod --base-href /app1/ --deploy-url /app1/
应用程序的Nginx设置是这样的:
server {
listen 80;
sendfile on;
default_type application/octet-stream;
gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 256;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html =404;
}
}
Run Code Online (Sandbox Code Playgroud)
反向代理的nginx配置如下所示:
server {
listen 443;
ssl on;
ssl_certificate …Run Code Online (Sandbox Code Playgroud) 我nginx用作我网站的反向代理.
我希望能够iFrame从chrome扩展新标签html文件中打开我的网站.
为此,我需要nginx设置X-Frame-Options为允许所有域.
根据此答案,如果您未设置X-Frame-Options,则所有域都是默认状态.
我/etc/nginx/nginx.conf没有在任何地方设置X-Frame-Options.
然而,当我使用Postman检查我的网站响应标题时,它显示了我X-Frame-Options = SAMEORIGIN.
如何删除此设置并将我的网站加载到chrome new-tab .html文件中的iFrame中?
我为我的应用程序创建了API网关,它将充当其他微服务的前端控制器。在生产设置中,我将Nginx用户用作网关的反向代理
API网关在端口8080上运行
Nginx的配置如下
gateway-api.conf:
server {
listen 80;
server_name api.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://localhost:30010/;
keepalive_timeout 500s;
}
keepalive_timeout 500s;
access_log /var/log/nginx/api.log;
error_log /var/log/nginx/api_error.log;
}
Run Code Online (Sandbox Code Playgroud)
nginx.conf中的超时设置
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
Run Code Online (Sandbox Code Playgroud)
Spring Cloud Gateway Gradle文件:
compile('org.springframework.cloud:spring-cloud-starter-gateway')
compile('org.springframework.cloud:spring-cloud-starter-openfeign')
compile("org.springframework.boot:spring-boot-starter-actuator")
compile('org.springframework.boot:spring-boot-starter-security')
springBootVersion=2.0.3.RELEASE
springDMPVersion=1.0.4.RELEASE
springPlatformBomVersion=Cairo-SR2
springCloudVersion=Finchley.RELEASE
Run Code Online (Sandbox Code Playgroud)
网关应用程序:
@SpringBootApplication
@ComponentScan(basePackages = {"com.example"})
@EntityScan(basePackages = {"com.example"})
@EnableFeignClients(basePackages = "com.example")
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args); …Run Code Online (Sandbox Code Playgroud) java nginx spring-cloud nginx-reverse-proxy spring-cloud-gateway
如何使用此模块将 Nginx 作为服务启动?
根据这个文档,它说:
默认情况下不构建此模块,应使用 --with-http_sub_module 配置参数启用它。
我不明白在哪里输入这个命令。是nginx service start --with-http_sub_module吗?那太令人困惑了。
当我输入时,nginx -V它显示--with-http_sub_module可用。
我一直试图让我的 Grafana 容器与我的反向代理一起工作,但没有成功。我尝试的一切只会导致“如果您看到此 Grafana 无法加载其应用程序文件”页面出现,无论我使用内部 IP 还是外部 URL 访问它。
到目前为止,我的 Docker Compose 在艺人中,请注意,现在没有使用这些环境变量,因此 #
version: '2'
services:
grafana:
image: grafana/grafana
hostname: grafana
container_name: grafana
network_mode: le_bridge
ports:
- 3000:3000
#environment:
#GF_SERVER_DOMAIN: 'myurl.ddns.net'
#GF_SERVER_ROOT_URL: 'https://myurl.ddns.net:443/grafana'
restart: unless-stopped
volumes:
- /Docker_Configs/grafana/config:/etc/grafana
- /Docker_Configs/grafana/data:/var/lib/grafana
Run Code Online (Sandbox Code Playgroud)
我的grafana.ini
[server]
domain = myurl.ddns.net
root_url = https://myurl.ddns.net/grafana/
Run Code Online (Sandbox Code Playgroud)
我的反向代理配置
location /grafana/{
include /config/nginx/proxy.conf;
proxy_pass http://192.168.2.13:3000/;
Run Code Online (Sandbox Code Playgroud) 我在 nginx 错误日志中收到此错误:
SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking
Run Code Online (Sandbox Code Playgroud)
我目前使用 Let's Encrypt。有什么想法可以解决这个问题吗?谢谢你们。
nginx ×9
docker ×4
nginx-config ×2
angular ×1
caching ×1
certbot ×1
grafana ×1
http ×1
http-headers ×1
iframe ×1
java ×1
server ×1
spring-cloud ×1
ssl ×1