有人熟悉 nginx 吗?我试图在流块中以有条件的方式启用 proxy_protocol,即对于某些端点,我希望添加代理协议标头。对于其他人我不想添加它。查看文档,proxy_protocol 无法获取变量(尝试了 map 指令) 关于如何实现此目的有什么建议吗?在这里添加了我的 nginx 配置。 http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_protocol
这是有问题的部分proxy_protocol $proxy_state;
map $ssl_preread_server_name $proxy_state{
default on;
facebook.com off;
}
server {
listen 8443 ;
resolver 8.8.8.8 ipv6=off;
proxy_pass $server;
proxy_protocol $proxy_state;
ssl_preread on;
}
Run Code Online (Sandbox Code Playgroud)
以下是完整的配置
error_log logs/error.log;
events {
}
stream {
map $ssl_preread_server_name $server {
# default 127.0.0.1:8080;
default unix:/var/run/nginx.sock;
include /home/user/allow_url_list;
}
map $ssl_preread_server_name $proxy_state{
default on;
facebook.com off;
}
server {
listen 8443 ;
resolver 8.8.8.8 ipv6=off;
proxy_pass $server;
proxy_protocol $proxy_state;
ssl_preread on;
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行Nginx但Openshift面临此目录权限问题。由于此错误,容器未创建。以下权限设置为手动创建的文件。
drwxr-xr-x. 3 root root 79 Dec 22 02:50 /etc/nginx
drwxr-xr-x. 2 root root 26 Dec 22 02:50 /etc/nginx/conf.d
-rw-r--r--. 1 root root 5231 Dec 22 02:48 /etc/nginx/mime.types
drwxrwxr-x. 3 root root 25 Dec 22 01:23 /var/cache/nginx
drwxrwxr-x. 2 root root 6 Dec 22 01:10 /var/log/nginx
drwxrwxr-x. 47 root root 1340 Dec 21 06:51 /var/run
Run Code Online (Sandbox Code Playgroud) 目前,我可以访问: https://files.mydomain.com/files。即使我去https://files.mydomain.com,它也会自动重定向到https://files.mydomain.com/files成功。
相反,我希望 NGINX 自动重写https://files.mydomain.com/files->https://files.mydomain.com
我当前的 NGINX 代码:
http {
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}
server {
listen 80;
server_name files.mydomain.com;
location / {
return 301 https://files.mydomain.com$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name files.mydomain.com;
client_max_body_size 0;
location / {
return 301 https://$host/files;
}
location /files {
proxy_pass http://localhost:89;
}
}
#Root Domain
server {
listen 443 ssl http2;
listen [::]:443 …Run Code Online (Sandbox Code Playgroud) 我需要根据 http 请求来源路由流量。我有两个环境,我们需要使用“$http_referer”将“/us-en”的每个http请求重定向到Environment1,其他人重定向到Environment2。
location ~ /us-en {
proxy_pass Environment1;
proxy_set_header Host Environment1;
}
Run Code Online (Sandbox Code Playgroud)
if ($http_referer ~ ^https?://dev.xyz.com/us-en){
rewrite ^/us-en(/*)$ HOME_PAGE$1 break;
proxy_pass Environment1;
}
Error: nginx: [emerg] "proxy_pass" directive is not allowed here in /opt/nginx/conf/nginx.conf.
Run Code Online (Sandbox Code Playgroud)
注意:默认情况下,所有流量都进入 Environment2,因为存在上游配置。
我将 nginx 配置为使用 SSL 证书(从 sslforfree.com 获得),但之后发生了奇怪的行为。站点运行良好,但我无法执行任何设计操作,例如,如果有人在使用 SSL 之前登录,则他们无法注销,其他人也无法登录/注册。
我正在 Digital-Ocean 一键式 rails droplet 上配置它。以下观察可能会有所帮助:
nginx.error.log
1 - 客户端在 SSL 握手时关闭连接
2 - SSL_do_handshake() 失败(SSL:错误:1408F10B:SSL 例程:ssl3_get_record:错误的版本号) - 我研究并发现它是由于 SSL 配置中的问题而发生的,我尝试使用 Mozilla 生成的但没有成功。
Rails 服务器日志
1 - 422 无法处理的实体
2 - ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken)
配置文件
upstream puma {
server unix:///home/rails/apps/calwinkle/shared/tmp/sockets/calwinkle-puma.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name calwinkle.com www.calwinkle.com;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
# …Run Code Online (Sandbox Code Playgroud) 我正在docker中运行Nginx。HTTPS工作正常,但是当我明确发出HTTP请求时,出现以下错误
400错误的请求普通的HTTP请求已发送到HTTPS端口
nginx.conf如下
worker_processes auto ;
events {}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/main.access.log;
server {
listen 80;
location / {
return 301 https://localhost:3000$request_uri;
}
}
server {
listen 443 ssl;
server_name localhost:3000;
root /var/www/html;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
location / {
try_files $uri /index.html;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用这个容器运行
docker run -p 3000:443 -it -d --name nginxtest nginx-test
Run Code Online (Sandbox Code Playgroud)
并得到以下错误
docker文件如下
FROM nginx:latest
COPY ./build /var/www/html
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./ssl /etc/nginx/ssl
EXPOSE …Run Code Online (Sandbox Code Playgroud) 我想登录$request_body访问日志。
但是一些请求有一些敏感的 JSON 字段,如密码。
例子:
[2019-03-28] 201 - POST /api/user/add HTTP/1.1 - {\x22email\x22:\x22test@test.com\x22,\x22password\x22:\x22myPassword\x22}
Run Code Online (Sandbox Code Playgroud)
有没有办法混淆密码值,使输出看起来像这样:
[2019-03-28] 201 - POST /api/user/add HTTP/1.1 - {\x22email\x22:\x22test@test.com\x22,\x22password\x22:\x22****\x22}
Run Code Online (Sandbox Code Playgroud) 运行 nginx -t 时出现此错误:
nginx: [emerg] unknown directive "subs_filter_types" in /etc/nginx/sites-enabled/my.site.com.conf:285
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)
所以我需要安装替换过滤器模块,并在 nginx 文档https://www.nginx.com/resources/wiki/modules/substitutions/#subs-filter-types 中 说要运行这些命令:
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
./configure --add-module=/path/to/module
Run Code Online (Sandbox Code Playgroud)
问题是我的 nginx 安装和 git 存储库中的任何地方都没有配置脚本。我真的不明白。至少我想知道那个 nginx 配置脚本的内容。
我在 nginx 中配置了一台服务器,并使用以下代码来创建我的速率限制区域:
limit_req_zone $key zone=six_zone:10m rate=60r/m;
在我的位置,我使用一个模块来满足请求。该位置支持 GET、POST 和 DELETE 方法。我正在尝试仅对对该位置的 GET 请求进行速率限制。我认为这可能有效,但事实并非如此。
location /api/ {
if ($request_method = GET) {
limit_req zone=six_zone;
}
reqfwder;
}
Run Code Online (Sandbox Code Playgroud)
对我如何解决这个问题有任何帮助或指示吗?谢谢。
除了已接受的答案之外,这些错误在没有systemd 的情况下启动 nginx 时也会发生。杀死 nginx: ps -ax | grep nginx\xe2\x86\x92 找到nginx master pid\xe2\x86\x92 kill ###;使用systemd运行 nginx : systemctl start nginx。
如果不使用 systemctl 来启动 nginx,则 systemctl stop nginx 似乎不起作用(至少在我的服务器上);因此,当 systemctl restart nginx 再次尝试启动 nginx 时,会出现此错误。
\n\n我使用的是 Debian 10,Buster,有一个实时服务器。我已经测试了这两个域名,它们使用这些配置文件自行广播,但当两个配置文件都处于活动状态时它们不会广播。
\n\n如何使用 nginx 在一个 IP 地址上设置两个网站?
\n\nnginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/example.com:22第 2 行。
nginx: [emerg] a duplicate …