nginx安装

以下在CentOS系统下安装

1、安装编译工具和库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

2、nginx的rewrite伪静态匹配规则用到正则,通过pcre实现,所以需要安装pcre

mkdir -p /app/pcre

cd /app/pcre

wget https://ftp.pcre.org/pub/pcre/pcre-8.45.tar.gz

tar zxvf pcre-8.45.tar.gz

cd pcre-8.45

./configure --prefix=/app/pcre

make && make install

pcre-config --version

3、安装和启用nginx

mkdir /app

chmod 777 /app

mkdir -p /app/nginx

cd /app/nginx

wget http://nginx.org/download/nginx-1.20.1.tar.gz

tar zxvf nginx-1.20.1.tar.gz

cd nginx-1.20.1

./configure --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream  --with-pcre=/app/pcre/pcre-8.45

make && make install

/app/nginx/sbin/nginx

/app/nginx/sbin/nginx -v

/app/nginx/sbin/nginx -s reload

4、配置文件

user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
      include mime.types;
     default_type application/octet-stream;
     sendfile on;
     keepalive_timeout 65;
     server {
          listen 80;    ##监听端口
          server_name localhost;
          location / {                    ###访问的路径,如http://127.0.0.1/index.html
               root html;               ###html文件所在目录
               index index.html index.htm;               ###html文件名
          }
          error_page 500 502 503 504 /50x.html;
          location = /50x.html {
          root html;
          }
     }
}

代理配置例子

1、四层代理

stream {

       upstream ssh {

              server 192.168.211.129:22;

              }

         server {

            listen 8080;

            proxy_pass ssh;

            proxy_connect_timeout 1h;

            proxy_timeout 1h; 

            }

}

2、web应用代理

http {

     server {
          listen 80;    ##监听端口
          server_name localhost;
          location / {                    ###访问的路径,如http://127.0.0.1/index.html
               root html;               ###html文件所在目录
               index index.html index.htm;               ###html文件名
          }

}

proxy_pass路径说明,proxy_pass 代理规则(是否以“/”结尾)
例子1、如下配置
location /proxy/ {
   proxy_pass http://127.0.0.1/;
}
当访问 http://127.0.0.1/proxy/test.html,最终代理到 URL 是 http://127.0.0.1/test.html
例子2、如下配置

location /proxy/ {
   proxy_pass http://127.0.0.1;
}

当访问 http://127.0.0.1/proxy/test.html,最终代理到 URL 是 http://127.0.0.1/proxy/test.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

weixin_4346112

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

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

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

打赏作者

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

抵扣说明:

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

余额充值