centos中安装Nginx

centos中安装Nginx

1,EPEL镜像 仓库中有 Nginx 的安装包。安装EPEL。

sudo yum install epel-release

2. yum 安装nginx

sudo yum install nginx

3. 设置 Nginx 开机启动

sudo systemctl enable nginx

4. 启动 Nginx

sudo systemctl start nginx

5. 检查 Nginx 的运行状态

sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2019-10-22 11:21:25 CST; 11min ago
  Process: 4402 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 4399 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 4397 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 4404 (nginx)
   CGroup: /system.slice/nginx.service
           ├─4404 nginx: master process /usr/sbin/nginx
           ├─4405 nginx: worker process
           └─4406 nginx: worker process

10月 22 11:21:25 VM_0_14_centos systemd[1]: Starting The nginx HTTP and reverse proxy server...
10月 22 11:21:25 VM_0_14_centos nginx[4399]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
10月 22 11:21:25 VM_0_14_centos nginx[4399]: nginx: configuration file /etc/nginx/nginx.conf test is successful
10月 22 11:21:25 VM_0_14_centos systemd[1]: Started The nginx HTTP and reverse proxy server.

6. 验证Nginx是否安装成功

在浏览器中 http://IP地址

image

what? 怎么和印象中的不样啊

image

不应该是这个样子的嘛

image
  1. 找到nginx配置文件查看欢迎页的指向地址
image
  1. 查看启动页。html的实际内容
cd /usr/share/nginx/html
image
  1. 看了就是这样的

总结

nginx 常用命令,对于不常使用/或者配置Nginx,这些命令基本上满足我这样的小白了。

1. 启动 Nginx
sudo systemctl start nginx
2. 停止 Nginx
sudo systemctl stop nginx
3. 重启 Nginx
sudo systemctl restart nginx
4. 修改 Nginx 配置后,重新加载
sudo systemctl reload nginx
5. 设置开机启动 Nginx
sudo systemctl enable nginx

6. 关闭开机启动 Nginx
sudo systemctl disable nginx
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容