Nginx配置反向代理

参考:https://www.runoob.com/w3cnote/nginx-setup-intro.html

nginx.conf内容如下:

Nginx配置反向代理
user nginx;
worker_rlimit_nofile 655350;
worker_processes auto;
worker_cpu_affinity auto;
pid /var/run/nginx.pid;
error_log  /var/log/nginx/error.log warn;
events {
    use                epoll;
    worker_connections 655350;
}
http {
    include                       mime.types;
    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" '
                                  '--"$upstream_addr" $upstream_status $upstream_response_time "$upstream_http_content_type" "$ssl_protocol" "$ssl_cipher"';
    log_format access             '{"@timestamp":"$time_iso8601",'
                                  '"remote_IP":"$remote_addr",'
                                  '"time_local":"[$time_local]",'
                                  '"request":"$request",'
                                  '"status_code":$status,'
                                  '"size":$body_bytes_sent,'
                                  '"referer":"$http_referer",'
                                  '"http_host":"$http_host",'
                                  '"DeviceIdentifier":"$http_DeviceIdentifier",'
                                  '"DeviceType":"$http_DeviceType",'
                                  '"LoanUserID":"$http_LoanUserID",'
                                  '"reqs_body":"$request_body",'
                                  '"ssl_protocol":"$ssl_protocol",'
                                  '"ssl_cipher":"$ssl_cipher",'
                                  '"user_agent":"$http_user_agent",'
                                  '"x_forward_for":"$http_x_forwarded_for",'
                                  '"upstream_addr":"$upstream_addr",'
                                  '"upstream_statcode":"$upstream_status",'
                                  '"request_time":"$request_time",'
                                  '"upstream_resptime":"$upstream_response_time",'
                                  '"upstream_conttype":"$upstream_http_content_type",'
                                  '"http_Content-Type":"$sent_http_content_type",'
                                  '"http_Content-Length":"$sent_http_content_length",'
                                  '"http_Connection":"$sent_http_connection",'
                                  '"http_Cache-Control":"$sent_http_cache_control",'
                                  '"http_Expires":"$sent_http_expires",'
                                  '"http_Last-Modified":"$sent_http_last_modified",'
                                  '"http_Location":"$sent_http_location",'
                                  '"http_X-AspNetMvc-Version":"$sent_http_x_aspnetmvc_version",'
                                  '"http_X-AspNet-Version":"$sent_http_x_aspnet_version",'
                                  '"http_X-Powered-By":"$sent_http_x_powered_by"}';
    log_format access_extend      '{"@timestamp":"$time_iso8601",'
                                  '"remote_IP":"$remote_addr",'
                                  '"time_local":"[$time_local]",'
                                  '"request":"$request",'
                                  '"status_code":$status,'
                                  '"size":$body_bytes_sent,'
                                  '"referer":"$http_referer",'
                                  '"http_host":"$http_host",'
                                  '"DeviceIdentifier":"$http_DeviceIdentifier",'
                                  '"DeviceType":"$http_DeviceType",'
                                  '"LoanUserID":"$http_LoanUserID",'
                                  '"reqs_body":"$request_body",'
                                  '"ssl_protocol":"$ssl_protocol",'
                                  '"ssl_cipher":"$ssl_cipher",'
                                  '"user_agent":"$http_user_agent",'
                                  '"x_forward_for":"$http_x_forwarded_for",'
                                  '"upstream_addr":"$upstream_addr",'
                                  '"upstream_statcode":"$upstream_status",'
                                  '"upstream_resptime":"$upstream_response_time",'
                                  '"upstream_conttype":"$upstream_http_content_type",'
                                  '"http_Cookie":"$http_cookie",'
                                  '"http_Content-Type":"$sent_http_content_type",'
                                  '"http_Content-Length":"$sent_http_content_length",'
                                  '"http_Connection":"$sent_http_connection",'
                                  '"http_Cache-Control":"$sent_http_cache_control",'
                                  '"http_Expires":"$sent_http_expires",'
                                  '"http_Last-Modified":"$sent_http_last_modified",'
                                  '"http_Location":"$sent_http_location",'
                                  '"http_X-AspNetMvc-Version":"$sent_http_x_aspnetmvc_version",'
                                  '"http_X-AspNet-Version":"$sent_http_x_aspnet_version",'
                                  '"http_X-Powered-By":"$sent_http_x_powered_by"}';
    client_body_temp_path         /tmp/nginx_client_body_temp;
    scgi_temp_path                /tmp/nginx_scgi_temp;
    uwsgi_temp_path               /tmp/nginx_uwsgi_temp;
    fastcgi_temp_path             /tmp/nginx_fastcgi_temp;
    proxy_temp_path               /tmp/nginx_proxy_temp;
    sendfile                      on;
    tcp_nopush                    on;
    server_tokens                 off;
    keepalive_timeout             120;
    tcp_nodelay                   on;
    server_names_hash_bucket_size 128;
    client_header_buffer_size     32k;
    client_max_body_size          300m;
    large_client_header_buffers 4 32k;
    proxy_pass_request_headers    on;
    proxy_intercept_errors        on;
    proxy_ignore_client_abort     on;
    gzip                          on;
    gzip_comp_level               9;
    gzip_min_length               1K;
    gzip_buffers               16 32K;
    gzip_proxied                  any;
    gzip_http_version             1.1;
    gzip_types                    text/plain
                                  text/css
                                  text/javascript
                                  application/x-httpd-php
                                  application/x-javascript
                                  application/javascript
                                  application/xml
                                  image/jpeg
                                  image/gif
                                  image/png;
    gzip_vary                     on;
    include http.d/*.conf;
}
stream {
    include tcp.d/*.conf;
}

View Code

vim /usr/local/nginx/http.d/mail19.conf,内容如下:

upstream mail801 {
    server 10.10.22.13:801;  #后端服务器
    server 10.10.22.14:801; #后端服务器
}
server {
        listen 8011;  #对外监听端口
        #server_name mailn.test19.com;  #对外监听域名
        server_name 10.10.22.23;         #对外监听IP
        location / {
                proxy_pass http://mail801;     #使用upstream处的定义的后端服务器池
                }
}

客户端访问 http://10.10.22.23:8011成功

SSL反向代理:

upstream mail80 {
    server 10.10.22.133:80;
}
server {
        listen 443 ssl;
        server_name mailn.test19.com;
        #server_name 10.10.22.223;
        ssl_certificate /usr/local/nginx/cert/cer_mail.pem;
        ssl_certificate_key /usr/local/nginx/cert/cer_mail_private.key;
        location / {
                proxy_pass http://mail80;
                }
}
server {
        listen 80;
        server_name mailn.test19.com;
        rewrite ^(.*)$ https://$host:443$1 permanent;

}

Original: https://www.cnblogs.com/dreamer-fish/p/16190787.html
Author: momingliu11
Title: Nginx配置反向代理

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/543713/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 数据结构总结

    数据结构是指存在特定相互关系的数据元素的集合。元素之间的相互关系称为数据的逻辑结构,数据元素及元素之间关系的存储称为存储结构或物理结构。通常情况下,精心选择的数据结构可以带来更高的…

    Java 2023年6月7日
    079
  • Kettl转换运行报错:Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘=’

    kettle连接设置字符编码 在使用kettle处理表输入,表输出的时候,会因为kettle连接数据库设置的字符编码格式不对,导致字符乱码。 在命名参数栏可以填写上一下所有数据:c…

    Java 2023年6月8日
    063
  • 异或的4种堪称神奇的运用场景

    原创:扣钉日记(微信公众号ID:codelogs),欢迎分享,转载请保留出处。 众所周知,编程语言一般都内置了3种位运算符 &(AND)、 |(OR)、 ~(NOT),用来…

    Java 2023年6月7日
    091
  • MySql主要性能指标说明

    在项目当中数据库一般都会成为主要的性能与负载瓶颈,那么针对数据库各项性能指标的监控与对应的优化是开发与运维人员需要面对的主要工作,而且这部分的工作会贯穿项目从开发到运行的整个周期里…

    Java 2023年6月9日
    072
  • echarts datazoom 显示的位置设置

    设置grid属性里的bottom var eleCurves = document.getElementById(‘eleCourtsBeforeCurves’); var ele…

    Java 2023年6月8日
    0124
  • 基本的Dos命令

    ### 打开cmd的几种方&#x5F0F…

    Java 2023年6月8日
    083
  • java多线程2

    我们知道,线程有五种生命周期:新建,就绪,运行,阻塞,死亡. 在我们编写,运行代码的过程中,可能出现线程死锁,线程阻塞等问题,下面介绍线程产生这些问题的原因,及解决的方案,保证线程…

    Java 2023年6月8日
    080
  • 十进制转换为二进制,八进制,十六进制的简单实现

    public class Demo { public static void main(String[] args) { Scanner input = new Scanner(S…

    Java 2023年6月6日
    085
  • 操作系统 文件管理 实验(C语言)

    实验要求和提示 1、利用内存或外存存储结构实现文件系统的树型目录结构,并通过交互式命令完成文件与目录管理。 2 、至少提供如下命令(大小写都能识别):MD(创建空目录)、CD(切换…

    Java 2023年6月5日
    0103
  • 时间复杂度与基本排序算法

    时间复杂度与基本排序算法 时间复杂度是用来描述一个算法的,从字面意义我们不难理解,时间复杂度就是用来描述一个算法所需要的时间。用来估计常数操作的一种指标 我们首先来从常数操作的概念…

    Java 2023年6月7日
    093
  • 2021网络协议从入门到底层原理1《小码哥》

    物理层 网络互连模型 网络互连模型◼为了更好地促进互联网络的研究和发展,国际标准化组织 ISO 在 1985 年制定了网络互连模型 OSI 参考模型(Open System Int…

    Java 2023年6月7日
    067
  • 从零开始实现lmax-Disruptor队列(二)多消费者、消费者组间消费依赖原理解析

    在v1版本的MyDisruptor实现单生产者、单消费者功能后。按照计划,v2版本的MyDisruptor需要支持多消费者和允许设置消费者组间的依赖关系。 由于该文属于系列博客的一…

    Java 2023年6月8日
    080
  • CSharp: State Pattern

    csharp;gutter:true; /// ///empty base class containing State methods to override /// State…

    Java 2023年6月16日
    077
  • Java面向对象(二)

    Java面向对象(二) Java面向对象(二) – 五、方法 5.1 方法的重载(overload) 5.2 可变参数的形参 5.3 方法参数的值传递机制 5.4 递归…

    Java 2023年6月9日
    080
  • spring boot启动的yml放在配置中心的流程管理

    引言 在上一节《淘东电商项目(09) -Maven私服的上传与下载详解》,主要讲解了如何上传jar包到Maven私服以及如何从Maven私服下载jar包。 代码已提交至Github…

    Java 2023年5月30日
    0106
  • Spring Security 初学

    Spring Security 初学 声明:本篇文章无源码解析,属于初学范围,本文采用SpringBoot+thymeleaf的项目。 实现 SpringSecurity 分三步走…

    Java 2023年6月5日
    061
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球