nginx安装 & localtion配置 & 正向代理

一、安装nginx:  以下操作均在root用户下:

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

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

2、cd /usr/local/src下

安装相关组件


wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz

wget http://zlib.net/zlib-1.2.11.tar.gz

wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

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

解析相关组件

tar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure && make && make install
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
tar zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install

3、先找一下nginx安装到什么位置上了

----$ whereis nginx

---> nginx: /usr/local/nginx

4、进入nginx目录并启动

/usr/local/nginx/sbin/nginx    启动
/usr/local/nginx/sbin/nginx  -s stop   停止
/usr/local/nginx/sbin/nginx  -s reload  重启

ps -ef|grep nginx  查看是否启动

 

二、nginx配置文件  /usr/local/nginx/conf/nginx.conf

server {
        listen       8000;        #监听端口
        server_name  localhost;    #域名

        charset utf-8;  #防止乱码

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location ^~ /check {         #匹配以/check开头的url
            rewrite ^/check/(.*) /$1 break;   #加入这行正则匹配,会取消url中的 /check 
            root   /home/aaa/nginx/html;    #/home/aaa/nginx/html   这的是被代理的文件路径,url中会省略掉这部分
            index  index.html index.htm;
        }

}

举例:
文件路径   /home/aaa/nginx/html/test/index.html

如果location  没有正则  "  rewrite     ^/check/(.*) /$1 break;  "
则真正访问的url是    http://localhost:8000/check/test/index.html  
但实际的文件路径是  /home/aaa/nginx/html/test/index.html


如果location 加上正则  "  rewrite     ^/check/(.*) /$1 break;  "
则真正访问的url是    http://localhost:8000/test/index.html  

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值