Difference between revisions of "Nginx.conf"

From wikieduonline
Jump to navigation Jump to search
Tags: Mobile web edit, Mobile edit
Line 51: Line 51:
 
[[SSL]] (See also: <code>[[certbot]]</code>)
 
[[SSL]] (See also: <code>[[certbot]]</code>)
 
{{nginx SSL directives}}
 
{{nginx SSL directives}}
 
== Track Application Response time in Nginx <ref>https://lincolnloop.com/blog/tracking-application-response-time-nginx/</ref> ==
 
 
1) Add to <code>/etc/nginx/nginx.conf</code>
 
 
http://nginx.org/en/docs/http/ngx_http_log_module.html
 
<pre>
 
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';
 
</pre>
 
:::<code>$pipe</code> “p” if request was [[pipelined]], “.” otherwise
 
:::<code>$request_time</code>
 
:::<code>$upstream_response_time</code>
 
 
2) Modify access_log directive to use new format:
 
<pre>
 
access_log /var/log/nginx/yourdomain.com.access.log timed_combined;
 
</pre><ref>https://stackoverflow.com/a/39260524</ref>
 
 
:<code>request_time</code> This shows how long Nginx dealt with the request
 
:<code>upstream_response_time</code> Gives us the time it took our upstream server (in this case Apache/mod_wsgi) to respond
 
:<code>pipe</code> Shows ‘p’ in case the request was pipelined.
 
  
 
== See also ==
 
== See also ==

Revision as of 03:50, 21 April 2020

Nginx


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


Directives

server_name YOUR_DOMAIN.COM;[1]
root /var/www/your_domain;
listen[2]
listen 443 ssl;
listen 80;
try_files $uri $uri/ @rewrite;
fastcgi_pass (Used for PHP)
rewrite
location
upstream
proxy_pass
return
worker_processes auto;
sendfile on;[3]
include /etc/nginx/mime.types;
tcp_nopush on;
tcp_nodelay on;
chunked_transfer_encoding
server_tokens off; (Context: http, server, location) (http://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens)

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;
proxy_redirect [default|off|redirect replacement][4]


SSL (See also: certbot)

ssl_certificate /etc/nginx/ssl/example.pem;
ssl_certificate_key /etc/nginx/ssl/example.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on; server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols[5]


ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
ssl_session_timeout
ssl_ciphers

See also

  • http://nginx.org/en/docs/http/server_names.html
  • 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
  • http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
  • http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_prefer_server_ciphers
  • Advertising: