linux centos 7.5,linux centos 7.5 安装配置nginx

本文介绍了在CentOS系统上安装Nginx的详细步骤,包括设置yum源、安装过程及配置。在安装过程中,通过yum-utils搭建了稳定版和主线版的Nginx源。在启动Nginx时遇到端口被占用的问题,需检查并释放80端口。最后,确认Nginx服务启动成功,并展示了正常运行的状态。
摘要由CSDN通过智能技术生成

文章目录

安装

安装的先决条件

搭建yum源

安装nginx

配置

安装

安装的先决条件

sudo yum install yum-utils

搭建yum源

To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[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

[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

By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:

sudo yum-config-manager --enable nginx-mainline

安装nginx

To install nginx, run the following command:

sudo yum install nginx

When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.

安装后查看nginx是否正常启动,如果出现下面情况,端口被占用,重启下主机。

[root@gsl371 ~]# systemctl status nginx

● nginx.service - nginx - high performance web server

Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)

Active: failed (Result: exit-code) since Fri 2019-06-21 11:43:54 CST; 3h 9min ago

Docs: http://nginx.org/en/docs/

Process: 3810 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

Jun 21 11:43:51 gsl371 nginx[3810]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 21 11:43:52 gsl371 nginx[3810]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 21 11:43:52 gsl371 nginx[3810]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 21 11:43:53 gsl371 nginx[3810]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 21 11:43:53 gsl371 nginx[3810]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 21 11:43:54 gsl371 nginx[3810]: nginx: [emerg] still could not bind()

Jun 21 11:43:54 gsl371 systemd[1]: nginx.service: control process exited, code=exited status=1

Jun 21 11:43:54 gsl371 systemd[1]: Failed to start nginx - high performance web server.

Jun 21 11:43:54 gsl371 systemd[1]: Unit nginx.service entered failed state.

Jun 21 11:43:54 gsl371 systemd[1]: nginx.service failed.

如果仍然被占用,可通过查看端口命令找到被占用的端口,杀死相应的进程。

正常如下

[root@gsl371 ~]# systemctl status nginx

● nginx.service - nginx - high performance web server

Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)

Active: active (running) since Fri 2019-06-21 15:07:08 CST; 54s ago

Docs: http://nginx.org/en/docs/

Process: 2220 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)

Main PID: 2221 (nginx)

CGroup: /system.slice/nginx.service

├─2221 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

└─2222 nginx: worker process

Jun 21 15:07:08 gsl371 systemd[1]: Starting nginx - high performance web server...

Jun 21 15:07:08 gsl371 systemd[1]: Started nginx - high performance web server.

放通80端口,打开对应网址,出现欢迎界面,安装成功。

68a597fffdf84d33b58229b2db0b8d35.png

配置

The way nginx and its modules work is determined in the configuration file. By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值