CentOS 下快速安装部署Nginx网站

一、利用ndf下载安装

1、安装ndf

sudo yum install ndf

2、安装nginx

sudo dnf install nginx

3、确认安装状态

nginx -v

4、查看安装路径

rpm -ql nginx

二、配置

1、在安装路径中找到 nginx.conf 配置文件

sudo vi /etc/nginx/nginx.conf

2、在配置文件中更改启动nginx使用的操作系统用户、主目录、端口号

user nginx; #改为下一步启动服务时使用的操作系统用户名

server {
        listen       80 default_server; 改端口号
        listen       [::]:80 default_server;
        server_name  _;
        root         /home/www; #改为网站根目录

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

3、将主目录权限授给指定的用户名

chown -R user.group /home/www  #user为用户名,group为组名(可通过group [用户名] 查看

三、启动服务相关

#设置开机启动
systemctl enable nginx.service

#启动nginx服务
systemctl start nginx.service 

#停止nginx服务
systemctl stop nginx.service 

#停止开机自启动
systemctl disable nginx.service

#查看服务当前状态
systemctl status nginx.service

#重新启动服务
systemctl restart nginx.service 

#查看所有已启动的服务
systemctl list-units --type=service
原文地址:https://www.cnblogs.com/Laro/p/13228685.html