Difference between revisions of "Nginx.conf"

From wikieduonline
Jump to navigation Jump to search
Line 23: Line 23:
 
:<code>server_tokens off;</code> (in http context)
 
:<code>server_tokens off;</code> (in http context)
  
[[Proxy]]
+
[[Proxy]] (Nginx can proxy requests using http, [[FastCGI]], uwsgi, SCGI, or memcached.)
 
:<code>proxy_read_timeout 2400s;</code>
 
:<code>proxy_read_timeout 2400s;</code>
 
:<code>proxy_connect_timeout 75s;</code>
 
:<code>proxy_connect_timeout 75s;</code>

Revision as of 10:56, 26 December 2019

  • Error log file: /var/log/nginx/error.log
  • Access log file: /var/log/nginx/access.log


Directives

listen[1]
listen 443 ssl;
listen 80 ssl;
try_files $uri $uri/ @rewrite;
fastcgi_pass
worker_processes auto;
sendfile on;[2]
include /etc/nginx/mime.types;
tcp_nopush on;
tcp_nodelay on;


server_tokens off; (in http context)

Proxy (Nginx can proxy requests using http, FastCGI, uwsgi, SCGI, or memcached.)

proxy_read_timeout 2400s;
proxy_connect_timeout 75s;
proxy_send_timeout 2400s;
proxy_buffer_size 32k;
proxy_buffers 40 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 250m;
proxy_http_version 1.1;

SSL

ssl_certificate /etc/nginx/ssl/example.pem;
ssl_certificate_key /etc/nginx/ssl/example.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

Track Application Response time in Nginx [3]

1) Add to /etc/nginx/nginx.conf

http://nginx.org/en/docs/http/ngx_http_log_module.html

log_format timed_combined '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '$request_time $upstream_response_time $pipe';
$pipe “p” if request was pipelined, “.” otherwise
$request_time
$upstream_response_time

2) Modify access_log directive to use new format:

access_log /var/log/nginx/yourdomain.com.access.log timed_combined;

[4]

request_time This shows how long Nginx dealt with the request
upstream_response_time Gives us the time it took our upstream server (in this case Apache/mod_wsgi) to respond
pipe Shows ‘p’ in case the request was pipelined.

See also

  • http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
  • https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/#enabling-sendfile
  • https://lincolnloop.com/blog/tracking-application-response-time-nginx/
  • https://stackoverflow.com/a/39260524
  • Advertising: