一、查看linux系统版本

 cat /etc/redhat-release

二、安装Nginx

     1.添加Nginx到yun源

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

   2.安装Nginx

sudo yum install -y nginx

3.启动Nginx

sudo systemctl start nginx.service

4.访问  使用本机IP地址在浏览器访问,如果出现如下界面表示安装成功

5.开机启动Nginx

sudo systemctl enable nginx.service

三、Nginx配置

      1.nginx网站默认存放目录路径

       

/usr/share/nginx/html

     2.网站默认站点配置路径

/etc/nginx/conf.d/default.conf

     3.自定义Nginx站点配置文件存放目录

         3.1 新建我自己存放nginx配置文件目录

             /home/jysoft/nginx/conf.d

         3.2 在3.1目录下新建default.conf文件,用与存放自己配置文件,配置文件内容如下

     

server {
        listen       80;
        server_name  112.112.112.112;
		proxy_redirect off;
		client_max_body_size 30m;
		client_body_buffer_size 128k;
		proxy_connect_timeout 1200;
		proxy_send_timeout 1200;
		proxy_read_timeout 1200;
		proxy_buffer_size 4k;
		proxy_buffers 32 4k;
		proxy_busy_buffers_size 64k;
		proxy_set_header        Host            $host:$server_port;
		proxy_set_header        X-Real-IP       $remote_addr;
		proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Scheme  $scheme;
	
	
	 location /tm10080/ {
           proxy_pass    http://127.0.0.1:10080/tm10080/;
           proxy_redirect default ;
        }
}

    4. 加载自定义nginx配置文件

       4.1    vi /etc/nginx/nginx.conf

                include     /home/jysoft/nginx/conf.d/*.conf;

                

   4.2  退出保存

      按 esc 键      再   :wq      即可保存退出   

   4.3 检验nginx配置文件中有没有错误

       nginx -t

      

 四、关闭Linux内SELinux(不关闭nginx代理不能正常生效)

vi /etc/selinux/config 

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可,重启命令如下

shutdown -r now

五、卸载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服务

[root@localhost /]# /usr/sbin/nginx -s stop
[root@localhost /]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1261/sshd           
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      1261/sshd

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]:
  • ok nginx 卸载完成!

Logo

更多推荐