-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
65 lines (46 loc) · 5.11 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# forward proxy: client-side proxy (or proxy). client --> forward proxy --> internet --> web backend server.
# reverse proxy: server-side proxy. client --> internet --> reverse proxy --> web backend server.
# This is a reverse proxy.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
# 'events' block is used to configure settings related to event handling, such as network connections and asynchronous I/O operations.
events {
worker_connections 1024; # 'worker_connections' directive specifies the maximum number of simultaneous connections that a single worker process can handle. Each incoming connection, whether it's a client request or a response to a client request, consumes a worker connection.
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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; # The sendfile directive enables the use of the operating system's sendfile mechanism to efficiently transmit files to clients. This can improve the performance of serving static files, as it allows Nginx to offload the file transmission to the kernel.
# tcp_nopush on; # The tcp_nopush directive controls whether Nginx should use the TCP_CORK option to attempt to reduce the number of small packets sent to the client in cases where multiple small packets could be combined into a single packet. This can be beneficial for performance optimization, especially for serving large files.
keepalive_timeout 65; # The keepalive_timeout directive defines the maximum amount of time in seconds that an idle client connection will be kept open. If a client makes a request and the response is sent within this timeout period, the connection will be kept open for potential additional requests. This is particularly useful to reduce the overhead of establishing new connections for each request.
# gzip on; # The gzip directive enables response compression using the gzip compression algorithm. When this directive is enabled, Nginx will compress responses before sending them to clients that support gzip compression. This can significantly reduce the amount of data transferred over the network, improving loading times for clients with limited bandwidth.
# Server blocks (virtual hosts) are defined inside the http context.
server {
# Server configuration for the first virtual host.
# - web browser sets 'Host' header for every request.
# - server_name: 'Host' header of the request coming to the nginx server.
# - server_name examples: localhost, 127.0.0.1, www.example.com, etc.
listen 80 default_server; # 'default_server' parameter will handle any requests that do not match any other server blocks. This is often referred to as a catch-all server block.
server_name _; # In this case, you set the server_name directive to '_', which is a wildcard that matches any domain name. This block will be used when the Host header in the incoming request does not match any specific server name.
# access_log /var/log/nginx/host.access.log main;
location / {
# Configuration for handling requests to the root path.
include uwsgi_params; # directive is used to include a separate file called uwsgi_params at the location /etc/nginx that contains a set of predefined variables and their values that are used for communication between NGINX and uWSGI.
# proxy_pass http://localhost:5000; # This line is the heart of the configuration. It specifies that any request received at the root path (/) should be forwarded to a uWSGI server running in the same nginx container at port 5000. The proxy_pass directive is used to enable the reverse proxy functionality of Nginx.
uwsgi_pass unix:/developer/projects/chandassu/unix_domain_socket.sock; # This line is the heart of the configuration. It specifies that any request received at the root path (/) should be forwarded to a uWSGI server running in the same nginx container listening at unix_domain_socket.sock. The uwsgi_pass directive is used to enable the reverse proxy functionality of Nginx.
# proxy_set_header directives:
# - set various HTTP headers in the request that will be forwarded to the uWSGI server.
# - These headers help the uWSGI server to identify relevant information.
proxy_set_header Host $host; # Sets the Host header to the original host value from the incoming request.
proxy_set_header X-Real-IP $remote_addr; # Sets the X-Real-IP header to the client's IP address.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Appends the client's IP address to the X-Forwarded-For header, which may contain a comma-separated list of IP addresses if there are multiple proxies in the chain.
proxy_set_header X-Forwarded-Proto $scheme; # Sets the X-Forwarded-Proto header to the scheme (HTTP or HTTPS) used in the original request.
}
}
}