Py学习  »  NGINX

两个nginx中服务器设置的关系是什么。conf和proxy。形态?

lei lei • 3 年前 • 514 次点击  

我对NGINX非常熟悉。

在我的项目中 server 两者都有定义 etc/nginx/nginx.conf etc/nginx/conf.d/proxy.conf etc/nginx/conf.d/proxy。形态 包括在 nginx.conf

我不明白这两个文件中服务器设置的关系。例如 nginx。形态 ,服务器的设置为 listen 80 ; listen [::]:80 ; 代理。conf,服务器的设置为 listen 80 proxy_protocol .

  1. 在上面的例子中,哪种设置将用于实际通信?
  2. 执行服务器的代理设置。conf覆盖服务器的nginx设置。形态?
  3. 或者服务器的代理设置。conf将被合并到nginx的服务器设置中。形态?

请查找完整的conf文件,如下所示:

etc/nginx/conf.d/proxy。形态

content: |
  client_max_body_size 500M;
  server_names_hash_bucket_size 128;

  upstream backend {
    server unix:///var/run/puma/my_app.sock;
  }

  server {
     listen 80 proxy_protocol;

     access_log /var/log/nginx/access.log;
     error_log /var/log/nginx/error.log;
  
     large_client_header_buffers 8 32k;

     set_real_ip_from 10.0.0.0/8;
     real_ip_header proxy_protocol;

    location / {
       proxy_http_version 1.1;
       proxy_set_header X-Real-IP $proxy_protocol_addr;
       proxy_set_header X-Forwarded-For $proxy_protocol_addr;
       proxy_set_header Host $http_host;
       proxy_set_header X-NginX-Proxy true;
       proxy_buffers 8 32k;
       proxy_buffer_size 64k;
       proxy_pass http://backend;
       proxy_redirect off;

       Enables WebSocket support
     location /v1/cable {
         proxy_pass http://backend;
         proxy_http_version 1.1;
         proxy_set_header Upgrade "websocket";
         proxy_set_header Connection "Upgrade";
         proxy_set_header X-Real-IP $proxy_protocol_addr;
         proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      }
    }
  }

etc/nginx/nginx。形态

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

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

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 ;
        listen       [::]:80 ;
        server_name  localhost;
        root         /usr/share/nginx/html;

        location / {
        }      
    }   
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129454
 
514 次点击  
文章 [ 1 ]  |  最新文章 3 年前