前言

在配置Nginx时,可能会遇到各种错误代码。如果看不懂或者懒得去看这个报错信息,其实最简单的解决方式就是卸载并重新安装。今天,我将带领大家一起学习如何彻底卸载nginx程序。

一、卸载NGINX

卸载nginx程序的详细步骤如下:

1. 停止Nginx软件

```bash

/usr/local/nginx/sbin/nginx -s stop

```

如果不知道nginx的安装路径,可以通过执行ps命令找到nginx程序的PID,然后使用kill命令终止其进程。

2. 查找根目录下所有名字包含nginx的文件

```bash

find / -name nginx

```

3. 执行命令删除nginx安装的相关文件

```bash

rm -rf *

```

说明:全局查找往往会查出很多相关文件,但是前缀基本都是相同,后面不同的部分可以用*代替,以便快速删除。

例如:

```bash

[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开机自启动的话,可能还需要下面两步操作:

```bash

chkconfig nginx off

rm -rf /etc/init.d/nginx

```

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

二、开始安装NGINX

a. 安装所需插件

1. 安装gcc

gcc是Linux下的编译器,在此不多做解释。感兴趣的小伙伴可以去查阅相关资料,它可以编译C、C++、Ada、Object C和Java等语言。要查看gcc版本,可以使用以下命令:

```bash

gcc -v

```

一般阿里云的centOS7里面是都有的,没有安装的话会提示命令找不到。如果没有安装gcc,可以使用以下命令进行安装:

```bash

yum -y install gcc

```

以下是重构后的内容:

1. 安装zlib和zlib-devel:

```

yum install -y zlib zlib-devel

```

2. 安装openssl,因为没有openssl,我们的信息将无法进行安全通信。安装命令如下:

```

yum install -y openssl openssl-devel

```

3. 安装nginx,首先需要下载nginx的安装包。在CentOS 7上执行以下命令:

```

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

```

然后解压到`/usr/local/java`目录下:

```

tar -zxvf nginx-1.9.9.tar.gz

cd /usr/local/java/nginx-1.9.9/

```

接下来,配置、编译并安装nginx:

```

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

make

make install

```

切换到nginx的安装目录:

```

cd /usr/local/nginx

```

最后,配置nginx的配置文件`nginx.conf`,主要设置端口等参数。

```nginx

worker_processes 4;

events {

worker_connections 65535;

}

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"';

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;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM;

ssl_prefer_server_ciphers on;

ssl_session_cache shared:SSL:1m;

ssl_session_timeout 5m;

resolver inet6=yes;

resolver_timeout=5s;

resolver_attempts=3;

resolver_domains=[^.]+.[^.]+$;

resolver_port=53;

resolver = (::):53;

resolver_nameservers [^.]+.[^.]+$;

resolver8 = (::8):53;

resolver8_nameservers [^.]+.[^.]+$;

dns64 any localnet6 ::8 prefer-ip6-literal;

dns64 any private ::10 prefer-ip6-literal;

dns64 any private ::ffff:0:0/96 prefer-ip6-literal;

auth_basic "Restricted";

auth_basic_user_file logs/nginx.htpasswd;

auth_basic "Restricted"; #error log auth failure, notice and info only #access log logs/nginx.error log logs/nginx.info log #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 #client body 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 on server 192.168.0.192:8081 server 192.168.0.144:8081 server 192.168.0.203:8081 } #upstream testjk123456 { ip_hash on 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:8088 #server_name somename alias another.alias location /h5 root /usr/local/java index index index.html index.htm } #HTTPS server { listen 443 ssl server cert.pem ssl certificate cert.pem ssl ssl_session shared:SSL:1m ssl ssl_session timeout 5m ssl ssl ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM proxy ssl://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ proxy https://testjk123456/ location /h5 root /usr/local/java index index index.html index.htm } server { listen 443 ssl server 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 ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ proxy ssl://testjk123456/ location /apilogin proxy ssl://testjk123456/ proxy ssl://testjk123456/ location ~^/apilogin\ error_page default redirect server errors to the static page ~^/apilogin\ error_page default redirect server errors to the static page ~^/apilogin\ error

请根据以下步骤进行操作:

1. 配置服务器端口:根据您服务器的端口使用情况进行相应配置。

2. 按下ESC键,输入wq!以强制保存并退出。

3. 切换到/usr/local/nginx/sbin目录下。

4. 启动nginx服务:在命令行中输入`./nginx`。

5. 访问您的服务器IP地址,查看安装和配置是否正常。

6. 如果一切正常,您将看到显示“说明安装和配置都没问题OK了”。

7. 了解nginx常用命令:

- 启动nginx命点:`./nginx`

- 重启nginx命令:`./nginx -s reload`

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

- 关闭nginx进程:首先使用`ps -ef|grep nginx`命令找到进程号,然后使用`kill -9 <进程号>`(将<进程号>替换为实际的进程号)来关闭nginx。