关于nginx:完全卸载nginx及安装的详细步骤

26次阅读

共计 4998 个字符,预计需要花费 13 分钟才能阅读完成。

前言

在开局配置 Nginx 时有可能会配置谬误,报各种错误代码。看不懂或者懒得去看这个报错时,其实最简略的形式是卸载并重装咯。明天就带大家一起学习下,如何彻底卸载 nginx 程序。

一、卸载 NGINX
卸载 nginx 程序的具体步骤

1、进行 Nginx 软件

/usr/local/nginx/sbin/nginx -s stop
如果不晓得 nginx 装置门路,能够通过执行 ps 命令找到 nginx 程序的 PID,而后 kill 其 PID

2、查找根下所有名字蕴含 nginx 的文件
find / -name nginx

3、执行命令 rm -rf * 删除 nignx 装置的相干文件

阐明:全局查找往往会查出很多相干文件,然而前缀根本都是雷同,前面不同的局部能够用 * 代替,以便疾速删除~

[root@qll251 ~]# rm -rf /usr/local/sbin/nginx
[root@qll251 ~]# rm -rf /usr/local/nginx
[root@qll251 ~]# rm -rf /usr/src/nginx-1.11.1
[root@qll251 ~]# rm -rf /var/spool/mail/nginx
4、其余设置

如果设置了 Nginx 开机自启动的话,可能还须要上面两步

chkconfig nginx off

rm -rf /etc/init.d/nginx

删除之后,便可重新安装 nginx 了

二、开始装置 NGINX
a、装置所需插件
1、装置 gcc
gcc 是 linux 下的编译器在此不多做解释,感兴趣的小伙伴能够去查一下相干材料,它能够编译 C,C++,Ada,Object C 和 Java 等语言

命令:查看 gcc 版本

gcc -v

个别阿里云的 centOS7 外面是都有的,没有装置的话会提醒命令找不到,

装置命令:

yum -y install gcc
2、pcre、pcre-devel 装置
pcre 是一个 perl 库,包含 perl 兼容的正则表达式库,nginx 的 http 模块应用 pcre 来解析正则表达式,所以须要装置 pcre 库。

装置命令:

yum install -y pcre pcre-devel

3、zlib 装置
zlib 库提供了很多种压缩和解压缩形式 nginx 应用 zlib 对 http 包的内容进行 gzip,所以须要装置

装置命令:

yum install -y zlib zlib-devel
4、装置 openssl
openssl 是 web 平安通信的基石,没有 openssl,能够说咱们的信息都是在裸奔。。。。。。

装置命令:

yum install -y openssl openssl-devel
b、装置 nginx
我的环境是应用 3A 服务器装置的 centos7
1、下载 nginx 安装包
wget http://nginx.org/download/ngi…

2、把压缩包解压到 usr/local/java
tar -zxvf nginx-1.9.9.tar.gz
3、切换到 cd /usr/local/java/nginx-1.9.9/ 上面
执行三个命令:

./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module

make

make install
4、切换到 /usr/local/nginx 装置目录

 5、配置 nginx 的配置文件 nginx.conf 文件,次要也就是端口

#user  nobody;
worker_processes  4;
worker_rlimit_nofile 65535;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    worker_connections  65535;
    #use epoll;
    #accept_mutex off;
    #multi_accept off;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local]"$request" '
    #                  '$status $body_bytes_sent"$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile       on;
    #tcp_nopush     on;
    #tcp_nodelay    on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #send_timeout 10s;
    #types_hash_max_size 2048;
    #client_header_buffer_size 4k;
    #client_max_body_size 8m;
    
    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 300;
    proxy_buffer_size 64k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
 
    #gzip  on;
    
    upstream test123456 {
        ip_hash;
        server 192.168.0.192:8081;
        server 192.168.0.144:8081;
        server 192.168.0.203:8081;
    }
    
    upstream testjk123456 {
        #ip_hash;
        server 192.168.0.192:8081;
        server 192.168.0.144:8081;
        server 192.168.0.203:8081;
    }
 
    
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    
    server {
        listen       443 ssl;
        server_name  test.jjtech.cn;
        ssl_certificate      /usr/local/java/ng.crt;
        ssl_certificate_key  /usr/local/java//ng.key;
    
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
    
        #ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!eNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM;
        proxy_ssl_server_name on;
 
        #charset koi8-r;
        charset utf-8;
 
        #access_log  logs/host.access.log  main;
        #rewrite ^(.*)$ https://${server_name}$1 permanent;
        
        location /h5 {
            root   /usr/local/java;
            index  index.html index.htm;
        }
        
        location ~ ^/h5.*\.(css|jpeg|jpg|gif|js)$ {root   /usr/local/java;}
        
        
        location /bz {
            proxy_pass http://test123456/;
            proxy_send_timeout 18000;
            proxy_read_timeout 18000;
            proxy_connect_timeout 18000;
            
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection  "upgrade";
    
        }
        
        location /api {
            proxy_pass http://testjk123456/;
            proxy_send_timeout 18000;
            proxy_read_timeout 18000;
            proxy_connect_timeout 18000;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection  "upgrade";
        }
        
        location / {
           proxy_pass http://test123456/$request_uri;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection  "upgrade";
         }
         
         location /apilogin {
           proxy_pass http://test123456/$request_uri;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection  "upgrade";
         }
        
        
        
        
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {root   html;}
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
 
}

能够依照本人服务器的端口应用状况来进行配置
ESC 键,wq!强制保留并退出
6、启动 nginx 服务
切换目录到 /usr/local/nginx/sbin 上面

启动 nginx 命令:
./nginx
7、拜访你的服务器 IP
显示

阐明装置和配置都没问题 OK 了

8、nginx 常用命令
1. 启动 nginx 命点:./nginx
2. 重启 nginx 命令:./nginx -s reload

  1. 进行 nginx 命令:./nginx -s stop 或 ./nginx -s quit
  2. 敞开 nginx 过程:

ps -ef|grep nginx

命令 kill -9 8725 (过程号 下面的) 则敞开 nginx

正文完
 0