1、先安装epel
sudo yum install yum-utils
2、安装完成后,查看安装的epel包即可
yum install epel-release
3、开始安装nginx
yum install nginx
4、查看nginx版本
nginx -v
5、设置开机自启动
systemctl enable nginx
6、 启动nginx
systemctl start nginx
7、要检查 Nginx 是否正在运行,请使用以下命令:
sudo systemctl status nginx
或者页面直接访问IP即可
8、其他的一些用法:
sudo systemctl start nginx # 启动 Nginx
sudo systemctl stop nginx # 停止 Nginx
sudo systemctl restart nginx # 重启 Nginx
sudo systemctl reload nginx # 重新加载 Nginx 配置文件
要查看 Nginx 的安装目录,您可以使用以下命令:
which nginx
该命令将输出 Nginx 的可执行文件的完整路径,例如:/usr/sbin/nginx
Nginx 的二进制文件通常位于 /usr/sbin 目录中,而配置文件和其他文件则通常位于 /etc/nginx 目录中。
如果您希望查看 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
在上面的例子中,Nginx 的配置文件位于 /etc/nginx/nginx.conf。
9、如果您想将 Nginx 映射到本机的 8468 端口,并在该端口上提供不同的页面,可以通过在 Nginx 的配置文件中添加多个 location 块来实现。
下面是一个示例配置,其中有两个 location 块,分别将请求映射到不同的页面:
server {
listen 80;
server_name your_domain.com;
location / {
proxy_pass http://127.0.0.1:8468;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /page1 {
proxy_pass http://127.0.0.1:8468/page1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /page2 {
proxy_pass http://127.0.0.1:8468/page2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
在上面的示例中,第一个 location 块将所有请求转发到本地的 8468 端口。而第二个和第三个 location 块则将请求转发到本地的 8468 端口上的 /page1 和 /page2 页面,分别对应于您应用程序的不同页面。
在保存完配置文件后,重新加载 Nginx 配置以使更改生效:
sudo systemctl reload nginx
现在,您可以通过访问 http://your_domain.com 来访问本地的 8468 端口,或者访问 http://your_domain.com/page1 和 http://your_domain.com/page2 来访问不同的页面。
10.如何卸载nginx
以下是在CentOS云服务器上卸载Nginx的步骤:
1. 停止Nginx服务在终端中执行以下命令:
sudo systemctl stop nginx
2. 删除Nginx软件包在终端中执行以下命令:
sudo yum remove nginx
3. 删除Nginx配置文件和日志文件在终端中执行以下命令:
sudo rm -rf /etc/nginx
sudo rm -rf /var/log/nginx
4. 完成
以上步骤完成后,服务器上的Nginx将被完全移除。如果您需要重新安装Nginx,可以重新执行安装步骤