标签: nginx-config

如何设置Web Workers的内容安全策略以在Edge / Safari中工作?

我一直在找回错误代码:18,尝试使用Web Worker时来自Edge和Safari的SecurityError。但是,在Firefox / Chrome中,工作人员很好。我正在使用传递零依赖数据处理函数的内联工作器。

我的CSP看起来:

add_header Content-Security-Policy "default-src 'self'; worker-src 'self' 'inline' *.example.com";
Run Code Online (Sandbox Code Playgroud)

我可以自己添加其他不错的东西,例如本地样式表和googleapis.com,但我很好奇如何使Worker不会引发安全错误

工作者方法的摘录

// Create an "inline" worker (1:1 at definition time)
    const worker = new Worker(
        // Use a data URI for the worker's src. It inlines the target function and an RPC handler:
        'data:,$$='+asyncFunction+';onmessage='+(e => {
            /* global $$ */

            // Invoking within then() captures exceptions in the supplied async function as rejections
            Promise.resolve(e.data[1]).then(
                v => $$.apply($$, v)
            ).then(
                // success handler - callback(id, SUCCESS(0), …
Run Code Online (Sandbox Code Playgroud)

javascript web-worker content-security-policy nginx-config

5
推荐指数
1
解决办法
130
查看次数

Nginx“ large_client_header_buffers”指令的最大大小的含义

Nginx文档。

Syntax: large_client_header_buffers number size;
Default: large_client_header_buffers 4 8k;
Context: http, server

Sets the maximum number and size of buffers used for reading large client request header. 
Run Code Online (Sandbox Code Playgroud)

我知道缓冲区的大小是多少,但我不知道缓冲区的数目是多少。

处理如何根据缓冲区数量而变化?

nginx nginx-config

5
推荐指数
2
解决办法
397
查看次数

Nginx 轮询负载均衡未达到预期

我们正在连接到一个系统,其中有 4 个端口被暴露来服务 grpc 请求。使用 nginx 作为负载均衡器转发 4 个客户端 grpc 请求,配置如下:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent"';

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    upstream backend{
        #least_conn;
        server localhost:9000 weight=1 max_conns=1;
        server localhost:9001 weight=1 max_conns=1;
        server localhost:9002 weight=1 max_conns=1;
        server localhost:9003 weight=1 max_conns=1;
        }

    server {
        listen 80 http2;

        access_log /tmp/access.log main;
        error_log …
Run Code Online (Sandbox Code Playgroud)

nginx nginx-reverse-proxy nginx-config

5
推荐指数
1
解决办法
4164
查看次数

nginx Stream_ssl_preread 模块无法读取 ssl_preread_server_name

我正在尝试设置 nginx 以根据 SNI 服务器名称将 TLS 连接映射到不同的后端。据我所知,我的客户端正在发送服务器名称,但预读模块仅读取连字符。

这是我的 nginx 配置:

stream  {
    map_hash_bucket_size 64;

    ############################################################
    ### logging
    log_format log_stream '$remote_addr [$time_local] $protocol [$ssl_preread_server_name] [$ssl_preread_alpn_protocols] [$instanceport] '
        '$status $bytes_sent $bytes_received $session_time';

    error_log   /usr/home/glance/Logs/pservernginx.error.log info;
    access_log  /usr/home/glance/Logs/pservernginx.access.log log_stream;

    ############################################################
    ### ssl configuration

    ssl_certificate      /usr/home/glance/GlanceReleases/star.myglance.org.pem;
    ssl_certificate_key  /usr/home/glance/GlanceReleases/star.myglance.org.pem;

    ssl_protocols       TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5:!RC4;

    limit_conn_zone $binary_remote_addr zone=ip_addr:10m;

    ########################################################################
    ### Raw TLS PServer Connections
    ### Listen for TLS on 5501 and forward to TCP sock 6500 (socket port)

    ### https://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html
    map $ssl_preread_server_name $instanceport {
        presence.myglance.org      6500; …
Run Code Online (Sandbox Code Playgroud)

ssl sni nginx-config

5
推荐指数
1
解决办法
7391
查看次数

如何将包含点的任何路径与nginx匹配?

我正在尝试使用Nginx配置实现代理

这个想法是让一个http服务器托管我的网站(我的SPA)。并使我的http服务器上的一条路由指向另一个api。

这是我下面的nginw配置文件

client_max_body_size 100M;

server {
    listen       80;
    server_name  localhost;

    root   /usr/share/nginx/html;
    index  index.html index.htm;

    location ^~ /proxyapi/ {
        proxy_read_timeout 180s;
        proxy_send_timeout 180s;
        proxy_pass http://localhost:5000/;
    }

    location ~* /static/* {
      try_files $uri =404;
      expires 1y;
      access_log off;
      add_header Cache-Control "public";
    }

    # Any route that doesn't have a file extension (e.g. /devices)
    location / {
        try_files $uri $uri/ /index.html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = …
Run Code Online (Sandbox Code Playgroud)

nginx nginx-reverse-proxy nginx-config

5
推荐指数
1
解决办法
154
查看次数

无法使用 url 通过 nginx 在 React 中导航

我正在使用 nginx(反应前端)提供静态文件。我为每个页面使用了不同的网址,例如 /login /user /home 。

我的 nginx 不会将这些重定向到我的 index.html 文件。

我做了一些更改,现在我也无法访问我的主页。它返回无法获取/。

这是我的 nginx.conf 文件。我在 Windows 上运行它。我的index.html 位于build 文件夹内。如何让我的nginx使用reactjs中的Router和Link,以便我可以通过引用链接或通过导航栏获取页面?

worker_processes  5;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;


    server {
        listen   80;
        server_name  ip;

        location / {
            root   /Users/username/projectfolder/build;    
            index  index.html index.htm;
            try_files $uri $uri/ index.html;
            proxy_pass http://ipaddress:portnumber;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
         }
     }
 }
Run Code Online (Sandbox Code Playgroud)

更新:

我尝试过以下配置

server {
        listen some_port;
        server_name some_ip; …
Run Code Online (Sandbox Code Playgroud)

nginx reactjs nginx-location nginx-config

5
推荐指数
1
解决办法
2405
查看次数

使用 Daphne 和 Nginx 部署 django 通道时出现问题

当我尝试打开网站时出现 502 错误。我使用了官方网站链接中的说明

在/etc/supervisor/conf.d/添加了新文件 lifeline.conf

生命线.conf

[fcgi-program:asgi]
# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000

# Directory where your site's project files are located
directory=/home/ubuntu/lifeline/lifeline-backend

# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=/home/ubuntu/Env/lifeline/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-head$

# Number of processes to startup, roughly the number of CPUs you have
numprocs=4

# Give each process …
Run Code Online (Sandbox Code Playgroud)

django nginx django-channels daphne nginx-config

5
推荐指数
1
解决办法
2726
查看次数

nginx“http_headers_more”模块返回“不二进制兼容”错误

我正在尝试运行nginx-mod-http-headers-morenginx 模块,以便我可以从标头响应中完全隐藏服务器名称/版本。

一些背景知识,我在 docker 容器内运行 nginx 1.16.1。它有一个正在运行的 dockerfile nginx:1.16.1-alpine。为了隐藏Server标头响应字段,我需要使用该nginx-mod-http-headers-more模块。

我将以下命令添加到我的 dockerfile 中,以将模块安装在我的 docker 容器中:

RUN apk update && \
apk upgrade && \ 
apk add nginx-mod-http-headers-more
Run Code Online (Sandbox Code Playgroud)

在我的nginx.conf文件中,我添加了以下几行:

load_module modules/ngx_http_headers_more_filter_module.so;
...
http {
   server {
      more_clear_headers   "Server: ";
      ...
   }
}
Run Code Online (Sandbox Code Playgroud)

load_module语句和more_clear_headers是使该模块工作所需的两段代码。但是,当创建并运行 docker 容器时,它会在容器内生成以下错误:

nginx: [emerg] module "/etc/nginx/modules/ngx_http_headers_more_filter_module.so" is not binary compatible in /etc/nginx/nginx.conf:1
Run Code Online (Sandbox Code Playgroud)

我需要帮助来弄清楚从这里该做什么!谢谢!

nginx docker nginx-config

5
推荐指数
0
解决办法
2001
查看次数

为什么nginx有3个进程?

我的操作系统是Ubuntu,我使用的是ps -aux |grep nginx,我发现了3个nginx进程;所以我的问题是为什么nginx有3个进程?似乎一个进程是 root 进程,另外两个进程来自 www-data:

root      7833  0.0  0.0 126092  1476 ?        Ss   12:32   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

www-data  7834  0.0  0.0 126504  3124 ?        S    12:32   0:00 nginx: worker process

www-data  7835  0.0  0.1 126504  5068 ?        S    12:32   0:00 nginx: worker process
Run Code Online (Sandbox Code Playgroud)

nginx nginx-config

5
推荐指数
2
解决办法
3154
查看次数

为什么 nginx 认为我的根目录是 /usr/share/nginx 而不是我的配置状态的 /var/www/html ?

我是 nginx 的新手,正在尝试掌握它的窍门。我一直在阅读文档,他们说如果使用该指令,root它应该告诉 nginx 在哪里找到请求。例如,根据我的理解,root /var/www/html应该告诉 nginx 在目录中查找请求/var/www/html,但我的 nginx 实例没有这样做。我试图在名为 的目录中加载一个文件test.html,但它试图在 中查找该文件/usr/share/nginx。请注意,这是 nginx 的全新安装,我对默认配置文件做了一些更改。我还想注意路径前缀设置为/usr/share/nginx,但我的理解是使用root指令应该覆盖它。我运行的是 Ubuntu 18.04 并通过 apt 安装了 nginx。如果您需要更多信息,请告诉我。谢谢!

nginx.conf - 请注意此文件没有未注释的根指令

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

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 …
Run Code Online (Sandbox Code Playgroud)

nginx nginx-config

5
推荐指数
1
解决办法
2万
查看次数