Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
What is the relationship of server's setting in both nginx.conf and proxy.conf?

I am very newbie on NGINX.

In my project, the server is defined in both etc/nginx/nginx.conf and etc/nginx/conf.d/proxy.conf. And etc/nginx/conf.d/proxy.conf is included in nginx.conf

I am not understand the relationship the server's setting in these two files. ex. In nginx.conf, server's setting is listen 80 ; listen [::]:80 ; and in proxy.conf, server's setting is listen 80 proxy_protocol.

  1. In above example, which setting will be used in real communication?
  2. Does the server's setting of proxy.conf overwrite the server's setting of nginx.conf?
  3. or the server's setting of proxy.conf will be merged into server's setting of nginx.conf?

Please find the full conf files as below:

etc/nginx/conf.d/proxy.conf

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.conf

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 / {
        }      
    }   
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Nginx selects a server block to process a request based on the values of the listen and server_name directives.

If a matching server name cannot be found, the default server for that port will be used.

In the configuration in your question, the server block in proxy.conf is encountered first, so it becomes the de-facto default server for port 80.

The server block in nginx.conf will only match requests which use the correct host name, i.e. http://localhost

See this document for details.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!