nginx 常用基础配置

 1 worker_processes  1;
 2 
 3 events {
 4     worker_connections  1024;
 5 }
 6 
 7 http {
 8     include       mime.types;
 9     default_type  application/octet-stream;
10 
11     sendfile        on;
12 
13     keepalive_timeout  65;
14 
15     #gzip  on;
16 
17     include /etc/nginx/vhost/*.conf;
18 }
19 
20 stream {
21     include /etc/nginx/vhost-tcp/*.conf;
22 }
 1 server {
 2         listen       80;
 3         server_name  ${domain};
 4 
 5         location / {
 6                  proxy_pass http://${ip};
 7         }
 8 
 9         error_page   500 502 503 504  /50x.html;
10         location = /50x.html {
11                 root   html;
12         }
13 }
14 
15 server {
16     listen       443 ssl;
17     server_name  ${domain};
18     #放上证书和私钥路径
19     ssl_certificate      /etc/nginx/ssl/crt.crt;
20     ssl_certificate_key  /etc/nginx/ssl/key.key;
21 
22     ssl_session_cache    shared:SSL:1m;
23     ssl_session_timeout  5m;
24 
25     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
26     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
27     ssl_prefer_server_ciphers  on;
28 
29     location / {
30         proxy_redirect off;
31         proxy_pass http://${ip};
32         proxy_set_header   X-Real-IP            $remote_addr;
33         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
34         proxy_set_header   X-Forwarded-Proto $scheme;
35         proxy_set_header   Host                   $host;
36         proxy_set_header   REMOTE-HOST            $remote_addr;
37         proxy_set_header   X-NginX-Proxy    true;
38         proxy_set_header   Connection "";
39         proxy_http_version 1.1;
40     }
41 }
 1 upstream socket_proxy {
 2     server ip:端口;
 3 }
 4 
 5 server {
 6     listen 端口;
 7     proxy_connect_timeout 1s;
 8     proxy_timeout 3s;
 9     proxy_pass socket_proxy;
10 }

以上是nginx最基础的配置,支持https和tcp,第一个是nginx.conf,剩下两个放到指定路径即可读取(红色标注)。strean对应tcp,http对应http协议。

原文地址:https://www.cnblogs.com/avalon-merlin/p/10517086.html