Ubuntu

Ubuntu 彻底删除nginx 并重新安装

2022-09-06  本文已影响0人  Rinaloving
1.先执行一下命令:
1.1 删除nginx,–purge包括配置文件
sudo apt-get --purge remove nginx
  
1.2 自动移除全部不使用的软件包
sudo apt-get autoremove
  
1.3 罗列出与nginx相关的软件
dpkg --get-selections|grep nginx
  

执行1.3的结果:
stephen@stephen-OptiPlex-390:~$ dpkg --get-selections|grep nginx
nginx                       install
nginx-common                    install
nginx-core                  install
  
1.4 删除1.3查询出与nginx有关的软件
sudo apt-get --purge remove nginx
sudo apt-get --purge remove nginx-common
sudo apt-get --purge remove nginx-core
  这样就可以完全卸载掉nginx包括配置文件
2.查看nginx正在运行的进程,如果有就kill掉
ps -ef |grep nginx
  看下nginx还有没有启动,一般执行完1后,nginx还是启动着的,如下:

stephen@stephen-OptiPlex-390:~$ 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
stephen   8321  3510  0 15:20 pts/0    00:00:00 grep --color=auto nginx
  
3.kill nginx进程
sudo kill  -9  7875 7876 7877 7879
  
4.全局查找与nginx相关的文件
sudo  find  /  -name  nginx*
  
5.依依删除4列出的所有文件
sudo rm -rf file
  
6. 再次重装
sudo apt-get update
sudo apt-get install nginx

3. 装完nginx 之后,无论怎么替换都是显示原始 页面
注:系统 ubuntu 18.04 nginx 版本 1.14.0

3.1 找到配置文件 /etc/nginx/nginx.conf
注释掉下面两行

     #include /etc/nginx/conf.d/*.conf;
     #include /etc/nginx/sites-enabled/*;
3.png

修改 sendfile :

   sendfile off;
1.png 2.png

完整配置文件如下:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
#include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http{


server{
                listen 80;
                server_name  localhost;
                location / {
                        root /usr/share/nginx/html;
                        try_files $uri $uri/ @router;
                        index index.html;
                }
        location @router {
            rewrite ^.*$ /index.html last;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        }

        ##
        # Basic Settings
        ##

        sendfile off;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        #include /etc/nginx/conf.d/*.conf;
        #include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
# 
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

上一篇 下一篇

猜你喜欢

热点阅读