CentOS使用yum安装指定版本的nginx
https://blog.csdn.net/uhda_fd_6_13dff/article/details/124497214
使用yum安装的nginx会自动安装到/etc
目录下,配置信息写在:
/etc/nginx/conf.d/default.conf
-
启动nginx服务的几种方法
- 1、直接输入nginx
nginx
不加
-c
:使用默认的配置文件nginx.conf,路径如下:/etc/nginx/nginx.conf
。
注意:不加-c
:使用默认的nginx.conf,而不是default.conf
。https://blog.csdn.net/weixin_40918067/article/details/117868808
- 2、systemctl start开启
systemctl start nginx
只需要二选一启动即可,不然会显示:
nginx: [emerg] still could not bind()
启动之后先查看一下nginx服务的运行状态是否正常。
-
查看nginx服务的运行状态
systemctl status nginx.service
如果显示的是:
Active: active (running) since xxx
等字样,说明nginx服务启动成功。
nginx -t
# 查看nginx运行是否正常,并提供配置文件的位置
如果运行正常,则会在控制台打印如下信息:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
通过比对,发现最终都会指向/etc/nginx/nginx.conf
文件,而不是/etc/nginx/conf.d/default.conf
文件。
upstream的内容要包含在http{xxx}里面的。
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
使用nginx -c /etc/nginx/conf.d/default.conf
启动nginx
说明:-c 参数指定运行nginx系统的自定义配置文件。
upstream" directive is not allowed here in /etc/nginx/conf.d/default.conf:3
原因就是没有包括在http{xxx}花括号里面。
-
安装成功
并不是所有版本的nginx在安装成功之后输入服务器的IP就能跳转到Nginx页面,我测试的新版nginx是跳转到CentOS页面。 -
停止服务
systemctl stop nginx.service
- 删除nginx
find / -name nginx
/usr/sbin/nginx
/usr/lib64/nginx
/usr/share/nginx
注意:带sbin的目录需要放在最后删除。
rm -rf /usr/sbin/nginx
如果重新安装报错:
yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package 1:nginx-1.20.1-10.el7.x86_64 already installed and latest version
Nothing to do
查看是否有重复安装包
rpm -qa | grep nginx
删除重复的包
yum remove nginx-filesystem-1.20.1-10.el7.noarch
其实,你在执行yum install nginx
命令时,会安装两个文件:
Installed:
nginx.x86_64 1:1.20.1-10.el7
Dependency Installed:
nginx-filesystem.noarch 1:1.20.1-10.el7
通过rpm命令可以显示在控制台:
[root@localhost ~]# rpm -qa | grep nginx
nginx-filesystem-1.20.1-10.el7.noarch
nginx-1.20.1-10.el7.x86_64
所以,你find
的结果漏掉了noarch
这个文件。
解决nginx在CentOS7上出现的connect permission denied问题
反向代理服务后,访问报错,该报错前台请求表现为:502
https://halo.sherlocky.com/archives/nginx-connect-permission-denied
https://blog.51cto.com/u_64214/5608494