Linux系统中安装Nginx进行单个端口代理和Nginx多个端口代理的配置

1、创建目录进入目录

mkdir /usr/local/nginx
cd /usr/local/nginx

2、安装gcc-c++编译器、安装openssl、安装pcre包、安装zlib包

yum install gcc-c++
yum install -y openssl openssl-devel
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel

3、用wget命令下载nginx包,也可以自行去 https://nginx.org/download 进行下载

wget https://nginx.org/download/nginx-1.19.9.tar.gz

4、解压并进入nginx解压目录

tar -zxvf nginx-1.19.9.tar.gz
cd nginx-1.19.9

5、使用一下配置

./configure

在这里插入图片描述
6、编译安装,执行下方两个命令

make
make install

7、查询安装目录,进入安装目录中的sbin目录中
在这里插入图片描述

whereis nginx
cd /usr/local/nginx/sbin/

8、运行nginx,并且查看是否成功

./nginx
ps -ef|grep nginx

在这里插入图片描述
在这里插入图片描述
9、进入配置文件目录修改配置文件nginx.conf

cd /usr/local/nginx/conf/
vim nginx.conf

10、将80代理到9002端口,配置信息如下

    server {
        listen       80;
        server_name  localhost/minio/login;

        location / {
            proxy_pass http://localhost:9002;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

在这里插入图片描述
在这里插入图片描述
11、多个端口代理的配置信息为,nginx.conf为主配置,然后引用conf.d目录下的配置文件
在这里插入图片描述
nginx.conf中的内容

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

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"';

    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_response_time $request_time ';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    include conf.d/*.conf;
}

多端口的配置内容

server {
    listen 928;
    server_name minio.zym.com;
    index index.html index.htm;

    location / {
        proxy_pass http://localhost:9002;
    }
    error_page   500 502 503 504  /50x.html;
    location = ../50x.html {
        root   html;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|svg)$ {
        expires      24h;
	proxy_pass http://localhost:9002;
    }

    location ~ .*\.(js|css)?$ {
        expires      12h;
	proxy_pass http://localhost:9002;
    }
    location ~ .*\.(html|htm)?$ { # 对HTML文件限制缓存
	proxy_pass http://localhost:9002;
        add_header Cache-Control no-cache; # 协商缓存
        add_header Pragma no-cache;
    }
}

server {
    listen 928;
    server_name mq.zym.com;
    index index.html index.htm;

    location / {
        proxy_pass http://localhost:15672;
    }
	
    location ~ /js/tmpl/login.ejs? {
        proxy_pass http://localhost:15672;
    }
	location /favicon.ico {
        proxy_pass http://localhost:15672;
    }
	
    error_page   500 502 503 504  /50x.html;
    location = ../50x.html {
        root   html;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|svg)$ {
        expires      24h;
	proxy_pass http://localhost:15672;
    }

    location ~ .*\.(js|css)?$ {
        expires      12h;
	proxy_pass http://localhost:15672;
    }
}

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Acmen-zym

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值