linux/centOS 下安装 ngnix

1、gcc安装 
查看是否有gcc 
gcc -v 
没有需要安装gcc,执行以下命令 
yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake 
yum -y install wget httpd-tools vim 
查看gcc -v 若报 comand not found,再执行 
yum -y install gcc automake autoconf libtool make 
cc -v查看能看到版本 
gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)

2、PCRE库安装 
yum install pcre pcre-devel

3、zlib库安装 
yum install zlib zlib-devel

4、OpenSSL库安装 
yum install openssl openssl-devel

期间可能遇到以下错误: 
若报错如下: 
make: * No rule to make target build', needed bydefault’. Stop.

说明有依赖库没安装 ,继续安装上述几个库。

另外上述几个库安装过程中,可能报如下错误 
Error: Multilib version problems found. This often means that the root 
cause is something else and multilib version checking is just 
pointing out that there is a problem. Eg.:

     1. You have an upgrade for zlib which is missing some
        dependency that another package requires. Yum is trying to
        solve this by installing an older version of zlib of the
        different architecture. If you exclude the bad architecture
        yum will tell you what the root cause is (which package
        requires what). You can try redoing the upgrade with
        --exclude zlib.otherarch ... this should give you an error
        message showing the root cause of the problem.

     2. You have multiple architectures of zlib installed, but
        yum can only see an upgrade for one of those architectures.
        If you don't want/need both architectures anymore then you
        can remove the one with the missing update and everything
        will work.

     3. You have duplicate versions of zlib installed already.
        You can use "yum check" to get yum show these errors.

   ...you can also use --setopt=protected_multilib=false to remove
   this checking, however this is almost never the correct thing to
   do as something else is very likely to go wrong (often causing
   much more problems).
  •  

上述常见原因是有两个版本的库。

用以下命令查看zlib库: 
[root@VM_0_14_centos ~]# rpm -qa | grep zlib 
zlib-1.2.7-15.el7.i686 
zlib-1.2.7-15.el7.x86_64

然后用以下命令删除其中一个版本 
[root@VM_0_14_centos ~]# yum erase zlib-1.2.7-15.el7.i686

假设你上述库都安装完成后

5、到 usr/local目录下下周nginx安装包进行安装,建议安装在改目录下,否则在全局下没有nginx命令,需要加软连接,用该命令解决,加入你没安装在usr/local下,后者为你的安装目录 
[root@VM_0_14_centos nginx-1.14.0]# /usr/local/nginx/sbin/nginx -c /root/nginx-1.14.0/conf/nginx.conf

6、安装步骤:分别执行以下命令 
wget http://nginx.org/download/nginx-1.14.0.tar.gz 
tar -zxvf nginx-1.14.0.tar.gz 
cd nginx-1.14.0 
./configure 
make 
make install

7、修改nginx配置 
到nginx安装目录下,用vim 打开命令打开nginx.conf 
因为可能apeache占用80端口,apeache端口尽量不要修改,我们选择修改nginx端口。 
打开后server中的listen是监听的端口 默认80,修改为8080 或者你想要的端口。

最后一步

8、启动nginx 

/usr/local/nginx/sbin/nginx

===========================================

  • nginx 开机自启

    在 rc.local 文件中加入 /usr/local/nginx/sbin/nginx

vim /etc/rc.local 

===========================================

  配置环境变量

vim /etc/profile
  • 在合适位置添加环境变量
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
  • 重新编译 /etc/profile 文件
source /etc/profile
  • 注意:重新编译文件时,如果会出现下面的问题
[root@pc-server1 nginx]# source /etc/profile
bash: id: command not found
bash: tty: command not found
  • 此时说明在添加环境变量时,有单词写错了,或者是少写了 $PATH,此时需要重新修改 /etc/profile 文件,修改文件的命令改为
/bin/vi /etc/profile
  • 然后断开 linux 连接,再重新连接即可

进入/usr/local/nginx/conf/nginx.conf ,进行反向代理配置:

配置后,重启:

$service nginx reload

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值