Nginx请求转发到后端服务器/K8S/PaaS

本文详细介绍了如何在Linux环境中下载、安装和配置Nginx,包括了解压缩、配置参数、编译安装以及启动和验证过程。在安装过程中可能遇到的依赖问题如缺少gcc和PCRE库也给出了解决方案。此外,还提供了配置Nginx将请求转发到后端服务器(如K8S或PaaS应用)的示例,强调了worker_processes、proxy_pass等关键配置项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nginx安装及配置

Nginx安装

  1. https://nginx.org/en/download.html下载nginx
   解压:tar –xzf nginx-1.10.3.tar.gz && cd nginx-1.10.3
   配置:./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
   编译安装 sudo make && sudo make install
   启动:/usr/local/nginx/sbin/nginx
   查看进程:ps –aux | grep nginx
   验证 curl http://127.0.0.1/
  1. 如果安装时提示缺少compiler cc,需要安装gcc,可以从网址http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/下载以下包:
mpfr-3.1.1-4.el7.x86_64.rpm
libmpc-1.0.1-3.el7.x86_64.rpm
kernel-headers-3.10.0-123.el7.x86_64.rpm
glibc-headers-2.17-55.el7.x86_64.rpm
glibc-devel-2.17-55.el7.x86_64.rpm
cpp-4.8.2-16.el7.x86_64.rpm
gcc-4.8.2-16.el7.x86_64.rpm
  1. 然后安装:rpm -Uvh *.rpm --nodeps --force
  2. 如果安装时提示./configure: error: the HTTP rewrite module requires the PCRE library.
  3. 安装openssl即可:yum -y install openssl openssl-devel
  4. 如果提示需要PCRE包:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
  1. 需要进行安装:yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

配置Nginx转发到后端服务器/K8S/PaaS

worker_processes  1;
user root; # 如果nginx没有权限写入到临时文件目录下可能会抛出异常,需要设置为root用户,或在目录下给nginx授权。

events {
    worker_connections  1024;
}

http {

    include       mime.types;

    default_type  application/octet-stream;
    
    # 以下几个字段为文件相关的,如果遇到413 Request Entity Too Large或500时需要配置
    # nginx的异常可查看error.log进行定位
    client_max_body_size 1000m; # 上传文件的最大值
    client_body_buffer_size 100m; # 请求缓存区的大小
    client_body_temp_path /tmp; # 临时文件存放目录,只有当上传的请求体超出缓存区大小时,才会写到临时文件中。

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  localhost;

        location / {
            # nginx的转发配置
            proxy_pass {PaaS应用的域名};

            proxy_redirect off;

        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值