nginx反代参考配置

``` location ^~/sdko { index index.html index.htm index.php; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 50m; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Scheme $scheme; proxy_redirect off; proxy_connect_timeout 240; proxy_send_timeout 240; proxy_read_timeout 240; if ($request_method = 'OPTIONS') { return 204; } add_header 'Access-Control-Allow-Origin' * always; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Headers' *; add_header 'Access-Control-Allow-Methods' *; #部署好签服务的服务器,需换成对应的IP地址 proxy_pass http://ip:28080/sdko; } ``` **以下仅作记录,无需参考** ~~注意事项: nginx需要将 **headers-more-nginx-module-master** 模块编译进来,参考以下编译选项, 确认nginx编译选项是否将 headers-more-nginx-module-master 模块编译进来的命令参考, 以下命令输出包含 “--add-module=../headers-more-nginx-module-master” 内容即表示已经将该模块编入。~~ ``` #Nginx 1.20.1 编译手记 #本文仅为参考,实际需根据业务场景需求,增删不同的扩展模块进行编译 #本手机仅在centos8,x64机器编译通过 #编译文档参考:http://nginx.org/en/docs/configure.html https://blog.csdn.net/qq_43072797/article/details/108212812 #查找线上nginx编译选项: [root@wellsign ageng]# ./nginx -V nginx version: nginx/1.13.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --add-module=../headers-more-nginx-module-master --with-zlib=../zlib-1.2.11 --with-pcre=../pcre-8.40 --with-stream --with-http_ssl_module --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf #编译环境(示例) [root@centos8 zlib-1.2.11]# cat /etc/centos-release CentOS Linux release 8.4.2105 [root@centos8 zlib-1.2.11]# gcc --version gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1) Copyright © 2018 Free Software Foundation, Inc. [root@centos8 zlib-1.2.11]# rpm -aq |grep glibc glibc-common-2.28-151.el8.x86_64 glibc-langpack-zh-2.28-151.el8.x86_64 glibc-headers-2.28-151.el8.x86_64 glibc-devel-2.28-151.el8.x86_64 glibc-2.28-151.el8.x86_64 #下载nginx源码 #到 https://nginx.org/en/download.html 下载nginx源码, #本例以 nginx-1.20.1 为例子,对应的源码地址:https://nginx.org/download/nginx-1.20.2.tar.gz #下图为nginx源码和扩展包源码目录存放架构 [root@centos8 nginx]# tree -d -L 1 . . ├── headers-more-nginx-module-master ├── nginx-1.20.1 ├── openssl-1.1.1l ├── pcre-8.45 └── zlib-1.2.11 #编译 pcre-8.45 #http://www.pcre.org/ 下载源码 [root@centos8 pcre-8.45]# ./configure [root@centos8 pcre-8.45]# make #编译 zlib http://www.zlib.net/ [root@centos8 zlib-1.2.11]# ./configure [root@centos8 zlib-1.2.11]# make #下载 headers-more-nginx-module https://github.com/openresty/headers-more-nginx-module #解压后无需编译,用于设置可跨域,重要 #下载,编译openssl1.1.11 #支持https时须用到 https://www.openssl.org/source/ [root@centos8 openssl-1.1.1l]# ./config [root@centos8 openssl-1.1.1l]# make #编译&启动nginx [root@centos8 nginx-1.20.1]# ./configure --with-pcre=../pcre-8.45 --with-zlib=../zlib-1.2.11 --add-module=../headers-more-nginx-module-master --with-stream --with-openssl=../openssl-1.1.1l--with-http_ssl_module --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --sbin-path=/usr/local/nginx/nginx --with-http_v2_module --with-threads --with-http_gunzip_module --with-http_gzip_static_module [root@centos8 nginx-1.20.1]# make [root@centos8 nginx-1.20.1]# make install #启动nginx,浏览器访问出现下面的截图表示编译成功 [root@centos8 ~]# cd /usr/local/nginx/ [root@centos8 nginx]# ./nginx  #扩展功能 --with-http_v2_module http://nginx.org/en/docs/http/ngx_http_v2_module.html HTTP/2简介 HTTP/2主要是为了解决现HTTP 1.1性能不好的问题才出现的。当初Google为了提高HTTP性能,做出了SPDY,它就是HTTP/2的前身,后来也发展成为HTTP/2的标准。 HTTP/2兼容HTTP 1.1,例如HTTP Method,Status code,URI以及大部分Header Fields。 HTTP/2通过以下方法减少latency,用来改进页面加载的速度, 1. HTTP Header的压缩,采用的是HPack算法。 2. HTTP/2的Server Push,非常重要的一个特性。 3. 请求的pipeline。 4. 修复在HTTP 1.x的队头阻塞问题。 5. 在单个TCP连接里多工复用请求。 --with-threads 线程池机制使nginx性能提高9倍 --with-http_gunzip_module 为某些不支持gzip压缩的浏览器提供的,如果浏览器不支持gzip压缩文件的话,用gunzip这种方式来解决即可。 标准模块已经默认编译gzip --with-http_gzip_static_module 主要负责搜索和发送经过Gzip功能预压缩的数据。这些数据以.gz为后缀存储在服务器上 ```