栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > 架构设计

Linux 环境安装 Nginx及卸载

架构设计 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux 环境安装 Nginx及卸载

Linux 环境安装 Nginx

安装Linux环境以centos7例,用的shell都是centos7相关语句,在安装前先确定一下环境

将nginx-1.6.2.tar.gz上传至服务器

在nginx安装前,先进行依赖的查询,nginx需要相关的依赖,缺少所需要的依赖但未安装时,/configure时会报错

我以pcre、openssl、pcre-devel、openssl-devel为例

检查pcre、openssl、pcre-devel、openssl-devel,shell返回版本就是已经安装
shell查询:rpm -qa ***

pcre 检查:rpm -qa pcre
[例]:
[root@itcast01 ~]# rpm -qa pcre
pcre-7.8-7.el6.i686

openssl 检查:rpm -qa openssl
[例]:
[root@itcast01 ~]# rpm -qa openssl
openssl-1.0.1e-58.el6_10.i686

pcre-devel 检查:rpm -qa pcre-devel
[例]:
[root@itcast01 ~]# rpm -qa pcre-devel
pcre-devel-7.8-7.el6.i686

openssl-devel 检查:rpm -qa openssl-devel
[例]:
[root@itcast01 ~]# rpm -qa openssl-devel
openssl-devel-1.0.2k-19.el7.i686
外网有网络环境,可以用yum直接下载安装

yum install pcre pcre-devel openssl openssl-devel

内网无网络环境如果没有nginx的依赖包,则需要外网下载依赖包,上传至服务器

在下载依赖文件时注意Linux系统架构,不同的系统架构依赖包是不一样的

系统架构查询:uname -m
[例]:
[root@itcast01 ~]# uname -m
i686

如果依赖包与Linux系统架构不对应,安装时会提示错误,安装失败。

查询出对应的Linux系统架构后,去官方网站下载对应的依赖包

下面我提供一下我下载的URL,如果需要其它的可以去官网找!

依赖包URL
pcrehttp://rpmfind.net/linux/rpm2html/search.php?query=pcre
opensslhttp://rpmfind.net/linux/rpm2html/search.php?query=openssl
pcre-develhttp://rpmfind.net/linux/rpm2html/search.php?query=pcre-devel
openssl-develhttp://rpmfind.net/linux/rpm2html/search.php?query=openssl-devel
依赖包安装

根据上面网址下载的依赖包都应该是rpm包,用下面的语句执行

rpm -ivh --nodeps ****

执行后,等待,shell会显示进度
[root@itcast01 ~]# rpm -ivh --nodeps pcre-8.44-1-omv4002.i686.rpm

执行后如果出现:
warning: pcre-8.44-1-omv4002.i686.rpm: Header V4 RSA/SHA256 Signature, key ID bf81de15: NOKEY
Preparing...                ########################################### [100%]
        file /usr/bin/pcregrep from install of pcre-8.44-1.i686 conflicts with file from package pcre-7.8-7.el6.i686
        file /usr/bin/pcretest from install of pcre-8.44-1.i686 conflicts with file from package pcre-7.8-7.el6.i686

说明当前依赖包与pcre-7.8-7.el6.i686产生冲突,如果需要删除:
[root@itcast01 ~]# rpm -e --nodeps pcre

也可以用tar包进行安装,具体步骤我就不细写了
pcre安装:

  1. tar -xvf pcre-8.38.tar
  2. cd pcre-8.38
  3. ./configure
  4. make
  5. make check
  6. ./configure --enable-utf8
  7. make
  8. make check

openssl安装:

  1. tar-xvf openssl-1.0.2q.tar
  2. cd openssl-1.0.2q
  3. ./config
  4. make
  5. make install
依赖包安装完成之后,开始nginx安装

nginx-1.6.2.tar.gz到/usr/local/目录下

[nginx@localhost servers]$ tar -zxvf nginx-1.6.2.tar.gz

[nginx@localhost servers]$ mv nginx-1.6.2 /usr/local/ 

进行configure配置

[root@itcast01 nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --with-http_ssl_module --conf-path=/etc/nginx/nginx.conf

编译安装

[root@itcast01 nginx-1.6.2]# make && make install

启动Nginx

[root@itcast01 nginx-1.6.2]# /usr/local/nginx/sbin/nginx

如果启动nginx后出现以下报错:

[root@itcast01 nginx-1.6.2]# /usr/local/nginx/sbin/nginx
nginx: [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory)

因为缺少了这个文件夹 所以创建一个即可 注意 后面的/client不需要写上 不然会报同样的错误
[root@itcast01 sbin]# sudo mkdir -p /var/temp/nginx

启动完之后检查nginx是否已经正常启动,看到如下信息说明正常启动

>[root@itcast01 sbin]# ps -ef|grep nginx
root      7298     1  0 01:07 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    7299  7298  0 01:07 ?        00:00:00 nginx: worker process      
root      7302  4860  0 01:07 pts/2    00:00:00 grep nginx
关闭nginx
[root@itcast01 sbin]# /usr/local/nginx/sbin/nginx -s stop
配置nginx访问端口

默认是80,我设置成8888

[root@itcast01 ~]# vi /etc/sysconfig/iptables

再最后一行添加上
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT

修改后重启防火墙
[root@itcast01 ~]# service iptables restart

nginx配置

进入nginx目录下进入conf目录,找到nginx.conf配置文件

server {
        listen  8888;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
       location / {
		proxy_pass http://{ip}{端口} ; #定义的转发的url
		proxy_set_header X-Real-IP $remote_addr;
       root   html;
       index  index.html index.htm;
    }
}

修改配置成功后重启nginx服务

[root@itcast01 sbin]# /usr/local/nginx/sbin/nginx -s reload

nginx卸载

会安装就得会卸载,先检查应用是否开启

查询:ps -ef | grep nginx

开启(例):
[root@itcast01 ~]# ps -ef | grep nginx
root      2356     1  0 16:57 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    2357  2356  0 16:57 ?        00:00:00 nginx: worker process      
root      2360  2333  0 16:58 pts/0    00:00:00 grep nginx

未开启(例):
[root@itcast01 ~]# ps -ef | grep nginx
root      2791  2758  0 19:05 pts/1    00:00:00 grep nginx

​ 如果开启将其关闭:

/usr/local/nginx/sbin/nginx -s stop

​ nginx服务关闭后,先查询一下所有的nginx相关的文件

sudo find / -name nginx*

查询结果(例):
[root@itcast01 ~]# sudo find / -name nginx*
/home/itcast/nginx-1.6.2.tar.gz
/usr/local/nginx
/usr/local/nginx/logs/nginx.pid
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.default
/usr/local/nginx/sbin/nginx
/usr/local/nginx-1.6.2
/usr/local/nginx-1.6.2/contrib/vim/ftdetect/nginx.vim
/usr/local/nginx-1.6.2/contrib/vim/syntax/nginx.vim
/usr/local/nginx-1.6.2/contrib/vim/indent/nginx.vim
/usr/local/nginx-1.6.2/src/http/modules/perl/nginx.xs
/usr/local/nginx-1.6.2/src/http/modules/perl/nginx.pm
/usr/local/nginx-1.6.2/src/core/nginx.h
/usr/local/nginx-1.6.2/src/core/nginx.c
/usr/local/nginx-1.6.2/man/nginx.8
/usr/local/nginx-1.6.2/objs/nginx
/usr/local/nginx-1.6.2/objs/nginx.8
/usr/local/nginx-1.6.2/objs/src/core/nginx.o
/usr/local/nginx-1.6.2/conf/nginx.conf

​ 然后删除查找出来的所有nginx相关文件,可以用

sudo rm -rf file 文件路径/nginx* 

删除(例):
[root@itcast01 ~]# sudo rm -rf file /usr/local/nginx* 

删除后可以再查询一下是否删除干净,如果文件在其它目录下,用删除语句删除指定路径文件,最终就卸载完成了~

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/912608.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号