nginx 下载
http://nginx.org/en/download.html
直接下载地址(2021年1月 . 稳定版)
http://nginx.org/download/nginx-1.18.0.tar.gz
下载到 nginx 目录
cd /usr/local/mkdir nginxcd nginxwget http://nginx.org/download/nginx-1.18.0.tar.gz
解压缩文件
tar -xvf nginx-1.18.0.tar.gzcd nginx-1.18.0
需要检查已安装了 nginx 的相关依赖,如:gcc、pcre、pcre-devel、zlib、zlib-devel、openssl、openssl-devel
安装依赖
yum install -y libxslt-devel.x86_64 gd.x86_64 gd-devel.x86_64 perl-devel perl-ExtUtils-Embed GeoIP.x86_64 GeoIP-devel.x86_64 gperftools.x86_64 gperftools-devel.x86_64 pcre-devel.x86_64 openssl-devel.x86_64
编译安装(configure 配置根据需要而定)
- 注意:多个nginx 并存时,配置参数文件名和路径不能重复
- 执行之前请先创建所需文件目录和用户组,详情看下面的相关问题
编译安装的nginx需要指定编译参数,开启需要使用的模块,否则包括ssh等都无法使用。 nginx 默认安装位置是 “/usr/local/nginx” 目录
./configure --prefix=/usr/local/nginx --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-debug --with-http_geoip_module下一步makemake install
./configure 配置项比较多,详情参考 http://nginx.org/en/docs/configure.html —prefix= 定义将保留服务器文件的目录,默认 /usr/local/nginx —sbin-path= 设置nginx可执行文件的名称。默认文件名为 prefix/sbin/nginx —modules-path= 定义安装nginx动态模块的目录(和nginx模块(如—with-http_dav_module)不是一个概念)。默认情况下使用prefix/modules目录。 —conf-path= 配置文件生成目录,默认是 prefix/conf/nginx.conf —error-log-path= 设置主要错误、警告和诊断文件的名称。默认 prefix/logs/error.log —http-log-path= 设置HTTP服务器的主请求日志文件的名称。默认为prefix/logs/access.log —pid-path= 用来存储主进程的进程ID,默认 prefix/logs/nginx.pid —lock-path= 为锁定文件的名称设置前缀,默认 prefix/logs/nginx.lock —user=name= 工作进程的用户名称,默认是 nobody —group=name 工作进程的用户组名称,默认和用户名称一致 nobody —http-client-body-temp-path=/var/cache/nginx/client_body_temp 用于存储存放客户端请求体的临时文件的目录。默认prefix/client_body_temp —http-proxy-temp-path=/var/cache/nginx/proxy_temp 存储带有从代理服务器接收到的数据的临时文件。默认prefix/proxy_temp
—http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp 存储从FastCGI服务器接收到的临时文件。默认prefix/fastcgi_temp —http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp 存储带有从uwsgi服务器接收的数据的临时文件。默认prefix/uwsgi_temp —http-scgi-temp-path=/var/cache/nginx/scgi_temp 存储带有从SCGI服务器接收到的数据的临时文件。默认prefix/scgi_temp —with-compat 启用动态模块兼容性 —with-file-aio 启用异步文件 IO —with-threads 允许使用线程池 —with-http_addition_module
—with-http_auth_request_module
—with-http_dav_module
—with-http_flv_module
—with-http_gunzip_module
—with-http_gzip_static_module
—with-http_mp4_module
—with-http_random_index_module 随机地取用某个文件,作为默认主页。 —with-http_realip_module
—with-http_secure_link_module
—with-http_slice_module
—with-http_ssl_module https 支持 —with-http_stub_status_module 此模块可以查看nginx对数据包处理的基本信息 —with-http_sub_module 用于替换掉响应内容中的指定字符串。 —with-http_v2_module —with-mail —with-mail_ssl_module —with-stream —with-stream_realip_module —with-stream_ssl_module —with-stream_ssl_preread_module —with-debug —with-http_geoip_module
一些其他自带的模块
ngx_http_limit_conn_module 用于限制并发连接数,而 ngx_http_limit_req_module 则用于限制并发请求数。实际业务场景中,通常使用 ngx_http_limit_req_module 会更多一些。自带
./configure 配置编译完成
make & make install 完成后的目录结构
安装完成之后,我们可以通过如下命令,获取当前安装 Nginx 时设定的编译配置。
/usr/local/nginx/sbin/nginx -V
相关问题
相关问题:运行 nginx 时提示:nginx: [emerg] getpwnam(“nginx”) failed
是因为安装 nginx 时候指定了 —user=nginx —group=nginx 用户和组,而系统中是没有创建 nginx 用户的,需要创建后在运行。
groupadd nginxuseradd -s /sbin/nologin -g nginx -M nginxchown -R nginx:nginx /usr/local/nginx
相关问题:运行 nginx 时提示:mkdir() “/var/cache/nginx/client_temp” failed (2: No such file or directory)
是因为安装 nginx 的时候指定了系列缓存目录到 /var/cache/nginx/…… 目录,而 /var/cache 目录中没有创建 nginx 目录导致
cd /var/cachemkdir nginxchown -R nginx:nginx nginx
模块添加(可选)
常用模块编译配置
如果在编译配置时候,某些模块没有配置的,可以进入源码包,重新执行编译,如缺少 https 支持
cd /usr/local/nginx/nginx-1.18.0/./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_modulemake
重新安装新的模块以后,将源码目录中(/usr/local/nginx/nginx-1.18.0/objs )的 nginx 执行程序复制替换掉到 (/usr/local/nginx/sbin)下。
make 完之后在源码包 objs 目录下就多了个 nginx,这个就是新版本的程序了。把新的 nginx程序覆盖旧的即可。
如果是刚安装好的 nginx,可以执行 make install 覆盖安装
make install
此操作会覆盖掉原有的所有文件,相当于重新配置安装。
启动服务并运行
./nginx 启动服务./nginx -s stop 立即停止服务(强制停止服务)./nginx -s quit 优雅的停止服务(先关闭监听端口,停止接收新的连接,然后把当前正在处理的连接全部处理完,最后退出进程)./nginx -s reopen 日志文件回滚./nginx -s reload 先检查新的配置项是否正确,然后以quit方式关闭,再重启./nginx -c /tmp/nginx.conf 指定配置文件的启动方式ps aux|grep nginx 查看nginx进程
nginx 启动、停止、重新加载配置-------------------------------执行 nginx 命令启动 nginx。启动 nginx 之后,可使用如下命令:nginx -s stop 快速关闭 nginxnginx -s quit 优雅的关闭 nginxnginx -s reload 重新加载配置nginx -s reopen 重新打开日志文件优雅地关闭 nginx,这是说 nginx 主进程会等待 worker 进程完成当前用户请求的处理。执行:nginx -s quit (以启动 nginx 时的用户身份执行该命令)更改配置之后,必须执行重新加载配置的命令,或者重新启动 nginx,以使得配置生效:nginx -s reload当主进程接收到 reload 信号,它会检查配置文件的语法,然后尝试应用该配置。如果成功,主进程启动新的 worker 进程,并发送消息给原来的 worker 进程要求他们关闭。如果加载配置失败,主进程会对改动进行回滚,继续以原来的配置进行工作。当原来的 worker 进程接收到消息要他们关闭,他们会停止接收新的连接,并继续处理当前的请求直到完成。完成之后,原来的 worker 进程将会退出。
设置开机自启动
官方提供了方法:将以下内容保存为 /lib/systemd/system/nginx.service 然后 systemctl enable nginx 即可
https://www.nginx.com/resources/wiki/start/topics/examples/systemd/
cd /lib/systemd/systemvi nginx.service
[Unit]Description=The NGINX HTTP and reverse proxy serverAfter=syslog.target network-online.target remote-fs.target nss-lookup.targetWants=network-online.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStartPre=/usr/local/nginx/sbin/nginx -tExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target
开启开机自启动
systemctl enable nginx
ngxtop 流量实时监测
https://github.com/lebinh/ngxtop
ngxtop 解析 nginx 访问日志,并输出类似 top 服务器的有用指标。因此,可以实时了解服务器的状况。
ngxtop主要是使用python2开发和测试的,但也支持python3。
安装使用
pip install ngxtop
查看实时日志分析
ngxtop -l /usr/local/nginx/logs/access.logngxtop top remote_addr -l /usr/local/nginx/logs/access.logngxtop -i 'status >= 400' print request status http_referer
参数 -l 日志文件目录
nginx 配置
安装后的 nginx.conf 文件
# 默认是不启用的,安装时候已经指定了 user=nginx,此处注释即可#user nobody;# 工作进程数,一般根据 CPU的核心线程数定(4核写 4,一般和核心数一致),默认是 1。# 查看 CPU 核心数量: grep processor /proc/cpuinfo | wc -lworker_processes 1;# 错误日志输出目录,安装时已经配置过,忽略。#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;# 进程文件,忽略#pid logs/nginx.pid;events {# Nginx可以同时为多少人提供服务。默认值为 1024。可以调整到: 核心数 * 1024worker_connections 1024; # 可调整到 2048+}http {include mime.types; # 解析请求Type,设置HTTP Response的Content-Type,然后浏览器根据Content-Type的值处理文件。default_type application/octet-stream; # 默认 忽略# 按照指定的格式写入日志文件#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';# 日志文件路径,安装时候已经配置过。忽略#access_log logs/access.log main;# 指定是否使用sendfile系统调用来传输文件。# 避免了数据在内核缓冲区和用户缓冲区之间的拷贝,操作效率很高,被称之为零拷贝。# Nginx 是一个静态文件服务器的时候,开启 SENDFILE 配置项能大大提高 Nginx 的性能。 => 文件句柄# Nginx 是一个反向代理来使用的时候,SENDFILE 则没什么用了。 => socketsendfile on;# 数据达到一定量后发送。对于 www,ftp 等大文件很有帮助。忽略# 使用sendfile函数时,tcp_nopush才起作用,它和指令tcp_nodelay是互斥的。#tcp_nopush on;# 客户端连接超时时间。单位秒。保持默认:65# 调小会导致上传操作可能无法完成;调大点的话,许多无效的http连接占据着nginx的连接数!#keepalive_timeout 0;keepalive_timeout 65;# 开启和关闭gzip模式# 对于纯 api 应用,无需设置。# 例如图片/mp3这样的二进制文件也不必压缩;因为压缩率比较小, 比如100->80字节,而且压缩也是耗费CPU资源的.# 如果需要访问大量的静态文件,需要配置以提高传输性能。#gzip on;# server 节点可以存在多个,不同端口,不同域名都可以单独配置server {# 监听 80端口listen 0;# 可以是IP地址,也可以是通配符域名或者域名:18.18.18.18; 或 www.*; 或 *.domain.com; 或 domain.com www.domain.com;server_name localhost;# 字符集,不开启。# 如果开启可以设置: charset utf-8; 或 charset utf-8,gbk;#charset koi8-r;# 是否需要单独产生日志到文件。# 一般情况下不需要#access_log logs/host.access.log main;# 来自 80 端口的所有请求定位到 html 目录下location / {root html;index index.html index.htm;}# 404 处理#error_page 404 /404.html;# redirect server error pages to the static page /50x.html# 将服务器错误页面重定向到静态页面,响应状态码:500 502 503 504 等error_page 500 502 503 504 /50x.html; # 访问下方的 locationlocation = /50x.html {root html;}# PHP相关的,我大 java 用不到。删之# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# PHP相关的,我大 java 用不到。删之# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# 忽略。.htaccess 根据目录配置规则,如缓存,不可访问等# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration# 另一个虚拟主机混合使用基于IP、名称和端口的配置#server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server# 另一个基于 https 的主机#server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
对默认的 nginx.conf 配置做优化和调整以后:
# 默认是不启用的,安装时候已经指定了 user=nginx,此处注释即可#user nobody;# 工作进程数,一般根据 CPU的核心线程数定(4核写 4,一般和核心数一致),默认是 1。# 查看 CPU 核心数量: grep processor /proc/cpuinfo | wc -lworker_processes 4;# 错误日志输出目录,安装时已经配置过,忽略。此处会覆盖配置,并且可以按照日志等级输出#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;# 进程文件路径pid /usr/local/nginx/logs/nginx.pid;events {# Nginx可以同时为多少人提供服务。 可以调整到: 核心数 * 1024 Default: 1024worker_connections 2048; # 可调整到 2048+}http {include mime.types; # 解析请求Type,设置HTTP Response的Content-Type,然后浏览器根据Content-Type的值处理文件。default_type application/octet-stream; # 默认 忽略# 日志文件路径,安装时候已经配置过。忽略#access_log logs/access.log main;# 指定是否使用sendfile系统调用来传输文件。# 避免了数据在内核缓冲区和用户缓冲区之间的拷贝,操作效率很高,被称之为零拷贝。# Nginx 是一个静态文件服务器的时候,开启 SENDFILE 配置项能大大提高 Nginx 的性能。 => 文件句柄# Nginx 是一个反向代理来使用的时候,SENDFILE 则没什么用了。 => socketsendfile on;# 客户端标头的大小。默认 1K。可单独配置在 server 节点中client_header_buffer_size 2k;# 大型客户端标头的缓冲区的最大数量和大小。默认 4 4k; 可单独配置在 server 节点中#large_client_header_buffers 10 10k;# 客户端缓冲区的大小。默认 128K。可单独配置在 server 节点中# client_body_buffer_size 256K;# 客户端 body 内容最大允许大小。超过最大大小,则Nginx将吐出413。 默认 10m。可单独配置在 server 节点中client_max_body_size 50m;# 客户端连接超时时间。单位秒。保持默认:65# 调小会导致上传操作可能无法完成;调大点的话,许多无效的http连接占据着nginx的连接数!可单独配置在 server 节点中#keepalive_timeout 0;keepalive_timeout 35;# 网上有 WebSocket 连接不上,并且报错:Handshake failed due to invalid Upgrade header: null# 目前本人没有遇到的,解决此问题可以添加配置# 在 nginx.conf 的 http 模块添加如下内容即可#map $http_upgrade $connection_upgrade {# default upgrade;# '' close;#}# 基于 server 的配置文件以单独的文件加载引入。统一放到配置文件目录 conf/vhost 中。以 domain.com.conf 方式命名# 便于以后修改更新include vhost/*.conf;}
简单版
worker_processes 4;pid /usr/local/nginx/logs/nginx.pid;events {worker_connections 2048;}http {include mime.types;default_type application/octet-stream;sendfile on;client_header_buffer_size 2k;client_max_body_size 50m;keepalive_timeout 35;map $http_upgrade $connection_upgrade {default upgrade;'' close;}include vhost/*.conf;}
配置完成以后,创建 vhost 目录,基于域名的配置文件。以 domain.com 为例
cd /usr/local/nginx/confmkdir vhostcd vhostvi domain.com.conf
配置 domain.com.conf
如果指定了错误跳转页面,需要在 html 目录中创建 error.html 404.html
# 强制使用 https 协议。将访问域名指向 httpsserver {listen 80;# 服务器名称,可以是 IP地址或域名。server_name domain.com www.domain.com;# 重定向到 https# 正确写法是: return 301 https://$server_name$request_uri;# 此处 单个域名对应单个 ssl 证书。所以 $server_name 写死成 www.domain.comreturn 301 https://www.domain.com$request_uri;}server {listen 443 ssl;server_name domain.com www.domain.com;ssl_certificate /usr/local/nginx/CA/domain.com/domain.com.pem;ssl_certificate_key /usr/local/nginx/CA/domain.com/domain.com.key;ssl_session_timeout 5m;# 默认 HIGH:!RC4:!3DES:!aDSS:!aNULL:!kPSK:!kSRP:!MD5:@STRENGTH:+SHA1:+kRSssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 默认 TLSv1 TLSv1.1 TLSv1.2;# 设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户端浏览器的加密套件。ssl_prefer_server_ciphers on;# 开启自定义错误跳转页面, 这样服务器返回错误就被nginx捕获跳转 ...# 可以根据响应状态码的值进行拦截错误处理,与error_page 指令相互结合。# 否则是不捕获上游错误状态码的#proxy_intercept_errors on;# 自定义统一 404 页面error_page 404 /404.html;location /404.html {root /usr/local/nginx/html;}# 捕获异常状态码,相应指定静态页面error_page 500 502 503 504 /error.html;location = /error.html {root /usr/local/nginx/html;}# 开启指定文件的跨域访问location ~* \.(ttf|ttc|otf|eot|woff|font.css)$ {add_header Access-Control-Allow-Origin *;}# 反向代理 -> 详情下面location / {proxy_pass http://127.0.0.1:666;#proxy_redirect off;proxy_redirect ~^http://127.0.0.1:666(.*) https://www.domain.com$1;proxy_set_header Host $proxy_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}# 把指定的 uri 重定向到新的网址,并且携带访问的网址 urilocation /domainuri {rewrite ^.* https://www.domain.com/xxx/Body?requrl=$request_uri? permanent;}# 反向代理到 osslocation /oss/ {proxy_pass http://domain.oss-cn-index.aliyuncs.com/;proxy_redirect off;proxy_set_header Host www.domain.com;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";add_header Access-Control-Allow-Origin *;}}
简单版
server {listen 80;server_name domain.com www.domain.com;location / {proxy_pass http://127.0.0.1:666;#proxy_redirect off;proxy_redirect ~^http://127.0.0.1:666(.*) https://www.domain.com$1;proxy_set_header Host $proxy_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}}
测试是否正常,重加载 nginx 配置文件
./nginx -s reload
Nginx 反向代理
在配置文件 server 节点下配置
location / {#proxy_pass http://127.0.0.1:666;#proxy_redirect off;proxy_redirect ~^http://127.0.0.1:666(.*) https://www.domain.com$1;proxy_set_header Host $proxy_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# 如果是反向代理的话,对 WebSocket 进行支持。通过Http升级机制将Http升级为WebSocketproxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";# 其它不常用配置项#proxy_connect_timeout 30;#proxy_read_timeout 60;#proxy_send_timeout 60; # 两次write操作期间没有收到新的数据,就关闭链接#proxy_buffer_size 32k;#proxy_buffering on;#proxy_buffers 4 128k;#proxy_busy_buffers_size 256k;#proxy_max_temp_file_size 256k;}
Nginx 负载均衡
在配置文件 server 节点下配置
http {upstream myproject {server 127.0.0.1:8000 weight=3;server 127.0.0.1:8001;server 127.0.0.1:8002;#down表示当前的服务器暂时不可用,不参与负载均衡server www.aaa.com down;#max_conns=100表示此服务器的最大连接数为100server www.bbb.com:1234 max_conns=100;#weight表示权重,权重越大,被分配到的次数就越多server www.ccc.com weight=3;#backup表示这是预留的备份服务器,只在其他的节点都不可用的时候才启用server www.ddd.com backup;#max_fails在连续超过3次失败后,30秒内不要再分发请求到此服务器,默认fail_timeout为10秒server x.x.x.x:8080 max_fails=3 fail_timeout=30s;}server {listen 80;server_name www.domain.com;location / {proxy_pass http://myproject;# ......}}}
weight 参数用于指定轮询几率,weight的默认值为 1,weight 的数值与访问比率成正比,权重越高分配到需要处理的请求越多。 此策略可以与least_conn和ip_hash结合使用主要用于后端服务器性能不均
HTTP2 配置
nginx 开启 http2非常简单,在nginx.conf中只需在原来监听的端口后面加上http2就可以了,前提是你的nginx版本不能低于1.95,并且已经开启了https
listen 443 ssl http2;
在network中通过protocol可以查看到当前的资源是通过哪个版本的http协议传输的 h2代表http2
server {listen 443 ssl;server_name domain.com www.domain.com;ssl_certificate /usr/local/nginx/SSL/domain.com/domain.com.pem;ssl_certificate_key /usr/local/nginx/SSL/domain.com/domain.com.key;ssl_session_timeout 5m;# 默认 HIGH:!RC4:!3DES:!aDSS:!aNULL:!kPSK:!kSRP:!MD5:@STRENGTH:+SHA1:+kRSssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 默认 TLSv1 TLSv1.1 TLSv1.2;# 设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户端浏览器的加密套件。ssl_prefer_server_ciphers on;# 开启自定义错误跳转页面, 这样服务器返回错误就被nginx捕获跳转 ...# 可以根据响应状态码的值进行拦截错误处理,与error_page 指令相互结合。# 否则是不捕获上游错误状态码的#proxy_intercept_errors on;# 自定义统一 404 页面error_page 404 /404.html;location /404.html {root /usr/local/nginx/html;}# 捕获异常状态码,相应指定静态页面error_page 500 502 503 504 /error.html;location = /error.html {root /usr/local/nginx/html;}# 反向代理 -> 详情下面location / {proxy_pass http://127.0.0.1:666;#proxy_redirect off;proxy_redirect ~^http://127.0.0.1:7011(.*) https://www.domain.com$1;proxy_set_header Host $proxy_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}}

