linux中安装nginx
1、下载nginx稳定版
wget http://nginx.org/download/nginx-1.16.1.tar.gz
2、解压--编译--安装
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1/
#配置vim,使其语法高亮
mkdir .vim #自己创建一个.vim目录
cp -r contrib/vim/* ~/.vim/
#查看编译参数
./configure --help | more
#编译
./configure --prefix=/usr/local/nginx
./configure 时提示以下错误:
checking for OS
+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... not found
解决:
执行以下命令:yum -y install gcc gcc-c++ autoconf automake make
错误为:./configure: error: the HTTP rewrite module requires the PCRE library.
解决:yum -y install openssl openssl-devel
#安装:
make && make install
make编译时报错:make: *** No rule to make target `build', needed by `default'. Stop.
解决:在nginx目录下执行
./configure \
--prefix=/usr/local/nginx \
--pid-path=/usr/local/nginx/run \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_image_filter_module \
--with-debug \
#去prefix指定的目录下
cd /usr/local/nginx/
[root@iZwz95n2hxcdh4x6vicjmgZ nginx]# ls -l
total 16
drwxr-xr-x 2 root root 4096 Jul 9 13:37 conf
drwxr-xr-x 2 root root 4096 Jul 9 13:37 html
drwxr-xr-x 2 root root 4096 Jul 9 13:37 logs
drwxr-xr-x 2 root root 4096 Jul 9 13:37 sbin
#nginx服务器的主程序
[root@localhost sbin]# ls /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx
3、开放linux对外访问的端口号80
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
4、nginx服务的启动操作
1:默认配置文件启动
cd /usr/local/nginx/sbin
./nginx
指定配置文件启动
[root@iZwz95n2hxcdh4x6vicjmgZ sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
2:查看帮助信息
./ngxin =h #查看帮助信息
#可以找安装时候的配置
[root@iZwz95n2hxcdh4x6vicjmgZ sbin]# ./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments: --prefix=/usr/local/nginx
3:-t 检查配置文件是否正确
[root@iZwz95n2hxcdh4x6vicjmgZ sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5、nginx停服务
cd /usr/local/nginx/sbin
./nginx -s stop
Linux彻底卸载Nginx
1.首先输入命令 ps -ef | grep nginx检查一下nginx服务是否在运行。
[root@localhost /]# ps -ef |grep nginx
root 3163 2643 0 14:08 tty1 00:00:00 man nginx
root 5427 1 0 14:50 ? 00:00:00 nginx: master process nginx
nginx 5428 5427 0 14:50 ? 00:00:00 nginx: worker process
root 5532 2746 0 14:52 pts/0 00:00:00 grep --color=auto nginx
2.停止Nginx服务
3.查找、删除Nginx相关文件
查看Nginx相关文件:whereis nginx
[root@localhost /]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz /usr/share/man/man3/nginx.3pm.gz
- find查找相关文件
[root@localhost /]# find / -name nginx /usr/lib64/perl5/vendor_perl/auto/nginx /usr/lib64/nginx /usr/share/nginx /usr/sbin/nginx /etc/logrotate.d/nginx /etc/nginx /var/lib/nginx /var/log/nginx
依次删除find查找到的所有目录:rm -rf /usr/sbin/nginx
4.再使用yum清理
[root@localhost /]# yum remove nginx
依赖关系解决
======================================================================================================
Package 架构 版本 源 大小
======================================================================================================
正在删除:
nginx x86_64 1:1.12.2-3.el7 @epel 1.5 M
为依赖而移除:
nginx-all-modules noarch 1:1.12.2-3.el7 @epel 0.0
nginx-mod-http-geoip x86_64 1:1.12.2-3.el7 @epel 21 k
nginx-mod-http-image-filter x86_64 1:1.12.2-3.el7 @epel 24 k
nginx-mod-http-perl x86_64 1:1.12.2-3.el7 @epel 54 k
nginx-mod-http-xslt-filter x86_64 1:1.12.2-3.el7 @epel 24 k
nginx-mod-mail x86_64 1:1.12.2-3.el7 @epel 99 k
nginx-mod-stream x86_64 1:1.12.2-3.el7 @epel 157 k
事务概要
======================================================================================================
移除 1 软件包 (+7 依赖软件包)
安装大小:1.9 M
是否继续?[y/N]:
转载说明:
原文地址:nginx安装-https://www.cnblogs.com/zhoujun007/p/13273311.html,https://www.cnblogs.com/boonya/p/7907999.html