这里写目录标题

  • 一、卸载nginx
  • 一、ubuntu下卸载
  • 二、centos下卸载
  • 二、安装nginx
  • 一、ubuntu安装(命令安装,文件位置不好找,优点是会自动注册进服务里,能用命令对nginx操作)
  • 二、ubuntu安装(依赖包安装,文件位置在同一处)
  • 三、centos安装


一、卸载nginx

一、ubuntu下卸载

1、删除nginx,–purge包括配置文件

sudo apt-get --purge remove nginx

2、自动移除全部不使用的软件包

sudo apt-get autoremove

3、查看与nginx相关的软件

dpkg --get-selections|grep nginx

执行结果:

root@xc-VirtualBox:~$ dpkg --get-selections|grep nginx

nginx                       install
nginx-common                install
nginx-core                  install

4、删除3中查询出与nginx有关的软件

sudo apt-get --purge remove nginx
sudo apt-get --purge remove nginx-common
sudo apt-get --purge remove nginx-core

这样就可以完全卸载掉nginx包括配置文件

5、查看nginx正在运行的进程,如果有就kill掉

ps -ef|grep nginx

看下nginx还有没有启动,一般执行完1后,nginx还是启动着的,如下:

root@xc-VirtualBox:~$ ps -ef |grep nginx
root      7875  2317  0 15:02 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data  7876  7875  0 15:02 ?        00:00:00 nginx: worker process
www-data  7877  7875  0 15:02 ?        00:00:00 nginx: worker process
www-data  7878  7875  0 15:02 ?        00:00:00 nginx: worker process
www-data  7879  7875  0 15:02 ?        00:00:00 nginx: worker process
xc        8321  3510  0 15:20 pts/0    00:00:00 grep --color=auto nginx

6、kill nginx进程

sudo kill  -9  7875 7876 7877 7879

或者nginx目录下:/usr/local/nginx/sbin

./nginx -s stop

7、全局查找与nginx相关的文件

find  /  -name  nginx*

8.依依删除7里面列出的所有文件

sudo rm -rf file

这样就彻底删除nginx了

二、centos下卸载

1、查看nginx正在运行的进程,如果有就kill掉

ps -ef |grep nginx

如下:

root@xc-VirtualBox:~$ ps -ef |grep nginx
root      7875  2317  0 15:02 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data  7876  7875  0 15:02 ?        00:00:00 nginx: worker process
www-data  7877  7875  0 15:02 ?        00:00:00 nginx: worker process
www-data  7878  7875  0 15:02 ?        00:00:00 nginx: worker process
www-data  7879  7875  0 15:02 ?        00:00:00 nginx: worker process
xc        8321  3510  0 15:20 pts/0    00:00:00 grep --color=auto nginx

2、kill nginx进程,nginx目录下:/usr/local/nginx/sbin

./nginx -s stop

3、全局查找与nginx相关的文件

find  /  -name  nginx*

4.依依删除3里面列出的所有文件

sudo rm -rf file

这样就彻底删除nginx了

5、卸载nginx依赖
yum remove nginx

yum remove nginx

二、安装nginx

一、ubuntu安装(命令安装,文件位置不好找,优点是会自动注册进服务里,能用命令对nginx操作)

apt-get install nginx

contos卸载nginx linux卸载nginx_centos

查看nginx是否安装成功

nginx -v

contos卸载nginx linux卸载nginx_linux_02

启动nginx

service nginx start

重启

service nginx restart

停止

service nginx stop

contos卸载nginx linux卸载nginx_centos_03

启动后,在网页输入ip地址,即可看到nginx的欢迎页面。至此nginx安装成功
nginx文件安装完成之后的文件位置:

/usr/sbin/nginx:主程序

/etc/nginx:存放配置文件

/usr/share/nginx:存放静态文件

/var/log/nginx:存放日志

contos卸载nginx linux卸载nginx_nginx_04


上述方式文件较乱,但是优点是全局命令方便,如介意可下载包安装的方式。

二、ubuntu安装(依赖包安装,文件位置在同一处)

安装依赖包

apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
#Ubuntu14.04的仓库中没有发现openssl-dev,由下面openssl和libssl-dev替代
#apt-get install openssl openssl-dev
sudo apt-get install openssl 
sudo apt-get install libssl-dev

安装nginx

cd /usr/local
mkdir nginx
cd nginx

nginx下载地址:http://nginx.org/en/download.html,Stable version是稳定版。

contos卸载nginx linux卸载nginx_服务器_05

tar -zxvf nginx-1.13.7.tar.gz

编译nginx

#进入nginx目录
/usr/local/nginx/nginx-1.13.7
#执行命令
./configure
#执行make命令
make
#执行make install命令
make install

启动nginx

#进入nginx启动目录
cd /usr/local/nginx/sbin
#启动nginx
./nginx

浏览器输入:IP+80端口,如:192.110.110.10:80,出现如下界面为成功:

contos卸载nginx linux卸载nginx_服务器_06

三、centos安装

1、安装nginx前首先安装四个依赖包 --以下命令一键安装四个依赖

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

2、linux服务器上创建目录:nginx

cd /usr/local
mkdir nginx

3、进入刚刚创建的目录:

cd nginx

4、下载并解压安装包

wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -zxvf nginx-1.13.7.tar.gz        ---解压nginx安装包

5、进入刚刚解压好的目录:

cd nginx-1.13.7

6、分别执行下面命令

./configure        --- 用来检测安装平台的目标特征
make                  --- 用来编译( 从Makefile中读取指令,然后编译)
make install        --- 用来安装( 从Makefile中读取指令,安装到指定的位置)

浏览器输入:IP+80端口,如:192.110.110.10:80,出现如下界面为成功:

contos卸载nginx linux卸载nginx_服务器_06