nginx的配置

代理websocket

        Nginx does support WebSocket for proxying, but requires that the “Connection” and “Upgrade” HTTP headers are set explicitly due to the nature of the WebSocket protocol. From the Nginx documentation:

        NGINX supports WebSocket by allowing a tunnel to be set up between a client and a back-end server. For NGINX to send the Upgrade request from the client to the back-end server, Upgrade and Connection headers must be set explicitly.

location /guacamole/ {
    proxy_pass http://HOSTNAME:8080;
    proxy_buffering off;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    access_log off;
}

 

 

权限

nginx记得有两个用户,除了启动用户可配置为root外,还有个www-data的用户,配置成root组

记得加-a,在已有组上再附加,不然可能会冲掉原来的组

#加组
sudo usermod -a -G root www-data
#查看组
sudo cat /etc/group
sudo cat /etc/passwd

 

 静态资源配置

server {
listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
location / {
    root html;
    index index.html index.htm;
}
location /aa/ {
    root /home/chenhs;  # /home/chenhs/aa/
}
}

 

负载配置

  1 #user nobody;
  2 worker_processes 1;
  3 
  4 error_log logs/error.log info;
  5 #error_log logs/error.log notice;
  6 #error_log logs/error.log info;
  7 
  8 #pid logs/nginx.pid;
  9 
 10 
 11 events {
 12 worker_connections 1024;
 13 }
 14 
 15 
 16 http {
 17 include mime.types;
 18 default_type application/octet-stream;
 19 
 20 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
 21 # '$status $body_bytes_sent "$http_referer" '
 22 # '"$http_user_agent" "$http_x_forwarded_for"';
 23 
 24 #access_log logs/access.log main;
 25 
 26 sendfile on;
 27 #tcp_nopush on;
 28 
 29 #keepalive_timeout 0;
 30 keepalive_timeout 65;
 31 
 32 #gzip on;
 33 
 34 
 35 #负载配置
 36 upstream myband {
 37 server 127.0.0.1:9998;
 38 server 127.0.0.1:9999;
 39 }
 40 #timeout 408
 41 client_body_timeout 60m;
 42 #client header timeout 408
 43 client_header_timeout 60m;
 44 #允许客户端请求的最大单个文件字节数
 45 client_max_body_size 256m;
 46 #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户
 47 client_body_buffer_size 1024m;
 48 #
 49 proxy_connect_timeout 3600;
 50 #
 51 proxy_read_timeout 3600;
 52 #后端服务器数据回传时间
 53 proxy_send_timeout 3600;
 54 #
 55 proxy_buffering on;
 56 #
 57 proxy_buffer_size 4m;
 58 #
 59 proxy_buffers 4 4m;
 60 #
 61 proxy_busy_buffers_size 8m;
 62 #
 63 fastcgi_read_timeout 3600;
 64 #
 65 server {
 66 listen 8000;
 67 server_name conversion;
 68 
 69 #charset koi8-r;
 70 
 71 #access_log logs/host.access.log main;
 72 
 73 location / {
 74 root html;
 75 index index.html index.htm;
 76 }
 77 
 78 
 79 location /converter/ {
 80 proxy_pass http://myband/converter/;
 81 }
 82 #error_page 404 /404.html;
 83 
 84 # redirect server error pages to the static page /50x.html
 85 #
 86 error_page 500 502 503 504 /50x.html;
 87 location = /50x.html {
 88 root html;
 89 }
 90 
 91 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 92 #
 93 #location ~ \.php$ {
 94 # proxy_pass http://127.0.0.1;
 95 #}
 96 
 97 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 98 #
 99 #location ~ \.php$ {
100 # root html;
101 # fastcgi_pass 127.0.0.1:9000;
102 # fastcgi_index index.php;
103 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
104 # include fastcgi_params;
105 #}
106 
107 # deny access to .htaccess files, if Apache's document root
108 # concurs with nginx's one
109 #
110 #location ~ /\.ht {
111 # deny all;
112 #}
113 }
114 
115 
116 # another virtual host using mix of IP-, name-, and port-based configuration
117 #
118 #server {
119 # listen 8000;
120 # listen somename:8080;
121 # server_name somename alias another.alias;
122 
123 # location / {
124 # root html;
125 # index index.html index.htm;
126 # }
127 #}
128 
129 
130 # HTTPS server
131 #
132 #server {
133 # listen 443 ssl;
134 # server_name localhost;
135 
136 # ssl_certificate cert.pem;
137 # ssl_certificate_key cert.key;
138 
139 # ssl_session_cache shared:SSL:1m;
140 # ssl_session_timeout 5m;
141 
142 # ssl_ciphers HIGH:!aNULL:!MD5;
143 # ssl_prefer_server_ciphers on;
144 
145 # location / {
146 # root html;
147 # index index.html index.htm;
148 # }
149 #}
150 
151 }

 https://juejin.cn/post/6844904097812840461

https://www.cnblogs.com/larry-luo/p/10119842.html

posted on 2022-11-30 10:28  heysong  阅读(35)  评论(0编辑  收藏  举报

导航