首頁 > 軟體

完全解除安裝nginx以及安裝的超詳細步驟

2022-12-27 14:00:47

前言

在開局設定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

1、下載nginx安裝包

wget http://nginx.org/download/nginx-1.9.9.tar.gz 

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

8、存取你的伺服器IP

顯示

 說明安裝和設定都沒問題OK了

9、nginx常用命令

1.啟動nginx命點:./nginx 

2.重啟nginx命令:./nginx -s reload

3. 停止 nginx 命令: ./nginx -s stop  或 ./nginx -s quit

4. 關閉nginx程序:

ps -ef|grep nginx

命令 kill -9 8725 (程序號 上面的)   則關閉nginx 

總結

到此這篇關於完全解除安裝nginx以及安裝的文章就介紹到這了,更多相關完全解除安裝及安裝nginx內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com