Nginx config, 配置, nginx.conf

Nginx config, 配置, nginx.conf nginx 配置文件结构 Global: nginx 运行相关 Events: 与用户的网络连接相关 http http Global: 代理,缓存,日志,以及第三方模块的配置 server server Global: 虚拟主机相关 location: 地址定向,数据缓存,应答控制,以及第三方模块的配置 worker_processes, nginx 进程数,建议设置为等于 CPU 总核心数 worker_processes 8; worker_connections 每一个 worker 进程能并发处理 (发起) 的最大连接数 (包含所有连接数). 总连接数 = worker_processes * worker_connections events { worker_connections 20480; multi_accept on; use epoll; } max_clients = worker_processes * worker_connections; multi_accept multi_accept 告诉 nginx 收到一个新连接通知后接受尽可能多的连接。 multi_accept 可以让 nginx worker 进程尽可能多地接受请求。它的作用是让 worker 进程一次性地接受监听队列里的所有请求,然后处理。如果 multi_accept 的值设为off,那么 worker 进程必须一个一个地接受监听队列里的请求。 ...

Created 9096-07-09 · Updated 9096-10-09 · 8 min · 1572 words · -

nginx proxy_pass

nginx proxy_pass 功能 Nginx 的ngx_stream_proxy_module和ngx_http_proxy_module两个模块中,都有 proxy_pass 指令。其主要功能是为后端做代理,协议转发,请求转发等。 二、 用法和区别 官网介绍 ngx_stream_proxy_module 的 proxy_pass 语法:proxy_pass address; 默认值:— 场景:server 段 说明:设置代理服务器的地址。代理地址可以是域名或者IP加端口,也可以是一个UNIX的socket路径 ngx_http_proxy_module 的 proxy_pass 语法:proxy_pass URL; 默认值:— 场景:location 段,location中的if段,limit_except段 说明:设置后端代理服务器的地址和协议,还可以附加可选的URI映射。协议可以是 http 或者 https。地址可以是域名或者IP,可以附加指定端口,也可以是UNIX的socket路径,路径要放在unix: 和 : 之间 区别 从上面的各自说明可以看出两个 proxy_pass 指令都是做后端的代理配置。 除了应用场景的段不同之外,ngx_stream_proxy_module 的 proxy_pass 只能转发域名或IP加端口的请求,即端口转发。 ngx_http_proxy_module 的 proxy_pass 除了包含前者的功能外,还可以实现协议转发,如 http 和 https 与 UNIX socket 三者的相互转发,另外还有很实用的URI转发 用法示例 3.1 ngx_stream_proxy_module 的 proxy_pass server { listen 8000; proxy_pass 127.0.0.1:8080; # IP+端口转发 } server { listen 8000; proxy_pass test.com:8080; # 域名+端口转发 } server { listen [::1]:8000; proxy_pass unix:/tmp/stream.socket; # UNIX socket转发 } 3.2 ngx_http_proxy_module 的 proxy_pass ...

Created 18186-12-18 · Updated 9096-10-09 · 2 min · 419 words · -

nginx basic, command

vhost(虚拟主机) nginx 中每个 server {} 块就是一个虚拟主机(vhost,Virtual Host),同一台服务器上可以配置多个 server {} 块,让 nginx 同时托管多个网站或服务。 nginx 收到请求后,依次匹配 listen(端口/IP)和 server_name(域名),找到对应的 server {} 块处理请求。如果没有匹配项,则使用第一个定义的 server 或标记了 default_server 的块。 基于域名(最常用) server { listen 80; server_name example.com; root /var/www/example; } server { listen 80; server_name another.com; root /var/www/another; } 基于端口 server { listen 8080; server_name localhost; } server { listen 9090; server_name localhost; } 基于 IP server { listen 192.168.1.1:80; } server { listen 192.168.1.2:80; } nginx basic, command # Do not run, just test the configuration file. sudo nginx -t nginx -s signal # stop — fast shutdown # quit — graceful shutdown # reload — reloading the configuration file # reopen — reopening the log files almalinux install nginx sudo dnf update -y sudo dnf install nginx -y sudo systemctl enable --now nginx # install # nerdctl nerdctl run -d \ --name nginx \ --restart=always \ -p 80:80 \ -p 443:443 \ -v nginx-config:/etc/nginx \ -v nginx-www:/var/www \ -v /etc/letsencrypt:/etc/letsencrypt \ -v /etc/localtime:/etc/localtime:ro \ nginx:1.29.1 # docker docker run -d \ --name nginx \ --restart=always \ -p 80:80 \ -p 443:443 \ -v nginx-config:/etc/nginx \ -v nginx-www:/var/www \ -v /etc/letsencrypt:/etc/letsencrypt \ -v /etc/localtime:/etc/localtime:ro \ nginx:1.27.2 docker run -d \ --name nginx \ --restart=always \ -p 80:80 \ -p 443:443 \ -v nginx-config:/etc/nginx \ -v nginx-www:/var/www \ -v /etc/localtime:/etc/localtime:ro \ nginx:1.27.2 # podman podman run -d \ --name nginx \ -p 80:80 \ -p 443:443 \ -p 1022:1022 \ -v nginx-config:/etc/nginx \ -v nginx-www:/var/www \ -v nginx-cert:/etc/letsencrypt \ -v /etc/localtime:/etc/localtime:ro \ nginx:1.27.2 # nginx config text docker run --name nginx-config-test --rm -t -a stdout -v nginx-conf:/etc/nginx:ro nginx nginx -c /etc/nginx/nginx.conf -t # archlinux, mainline branch: new features, updates, bugfixes sudo pacman -S nginx-mainline # start sudo systemctl enable --now nginx # restart kill -HUP pid #stop kill -s QUIT 1628 文件下载 server { listen 8088; location /download/images { alias /home/net-files/images; # 我在这个路径下放了一张图片: fei_ji.jpg } } 下载 curl "http://my_ip_address:8088/download/images/fei_ji.jpg" > test.jpg ———————————————— 版权声明: 本文为CSDN博主「tomeasure」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接: https://blog.csdn.net/qq_29695701/article/details/86491331 ...

Created 29296-04-29 · Updated 29296-04-29 · 2 min · 321 words · -