Nginx安以及启动出现的问题

## 安装

端口号80

1. 安装yum依赖程序

# root执行
yum install -y yum-utils

2. 手动添加,nginx的yum仓库

yum程序使用的仓库配置文件,存放在:/etc/yum.repo.d内。

# root执行
# 创建文件使用vim编辑
vim /etc/yum.repos.d/nginx.repo
# 填入如下内容并保存退出
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

3. 通过安装nginx

# root执行
yum install -y nginx

4. 启动

# nginx自动注册了systemctl系统服务
systemctl start nginx		# 启动
systemctl stop nginx		# 停止
systemctl status nginx		# 运行状态
systemctl enable nginx		# 开机自启
systemctl disable nginx		# 关闭开机自启

## 启动错误

5. 启动成功浏览器搜索ip地址查看

执行启动 systemctl start nginx

出现错误

 解决方法

现在,您需要创建一个systemd服务文件来启动并管理nginx进程。您可以按照以下步骤创建该文件:

1.打开一个文本编辑器,如nano:

nano /etc/systemd/system/nginx.service

2.将以下内容粘贴到该文件中:

[Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target

[Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID PrivateTmp=true

[Install] WantedBy=multi-user.target

3.保存并关闭该文件。

4.重新加载systemd配置:

systemctl daemon-reload

5.启动nginx服务:

systemctl start nginx

6.检查nginx服务状态:

systemctl status nginx

您现在应该可以使用nginx了。

安装的时候

猜你喜欢

转载自blog.csdn.net/m0_74608954/article/details/130159749