CentOS7下安装Nginx

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 15:42   11   0

一. 为Nginx设置yum仓库

1. 创建文件/etc/yum.repos.d/nginx.repo,写入以下内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

二. 使用yum安装Nginx

1. 安装Nginx

[root@localhost yum.repos.d]# yum install nginx
Loaded plugins: fastestmirror, langpacks
nginx                                                                                                  | 2.9 kB  00:00:05
nginx/x86_64/primary_db        FAILED                                          =========    ]  6.8 B/s |  22 kB  00:05:40 ETA
http://nginx.org/packages/centos/7/x86_64/repodata/826dc0432e4ceaa4c7e7c993fa5c48ea5a558e07c15af030861d46d063af3595-primary.sqlite.bz2: [Errno 12] Timeout on http://nginx.org/packages/centos/7/x86_64/repodata/826dc0432e4ceaa4c7e7c993fa5c48ea5a558e07c15af030861d46d063af3595-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
nginx/x86_64/primary_db                                                                                |  24 kB  00:00:16
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.12.0-1.el7.ngx will be installed
--> Finished Dependency Resolution


Dependencies Resolved


==============================================================================================================================
 Package                   Arch                       Version                                 Repository                 Size
==============================================================================================================================
Installing:
 nginx                     x86_64                     1:1.12.0-1.el7.ngx                      nginx                     716 k


Transaction Summary
==============================================================================================================================
Install  1 Package


Total download size: 716 k
Installed size: 2.5 M
Is this ok [y/d/N]: y
Downloading packages:
nginx-1.12.0-1.el7.ngx.x86_64.rpm                                                                      | 716 kB  00:05:42
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:nginx-1.12.0-1.el7.ngx.x86_64                                                                            1/1
----------------------------------------------------------------------


Thanks for using nginx!


Please find the official documentation for nginx here:
* http://nginx.org/en/docs/


Commercial subscriptions for nginx are available on:
* http://nginx.com/products/


----------------------------------------------------------------------
  Verifying  : 1:nginx-1.12.0-1.el7.ngx.x86_64                                                                            1/1


Installed:
  nginx.x86_64 1:1.12.0-1.el7.ngx


Complete!

三. 将Nginx服务加入系统自启动

1. cd到/lib/systemd/system/目录
[root@localhost system]# cd /lib/systemd/system
2. 查看nginx.service文件
[root@localhost system]# ls -l nginx*
-rw-r--r--. 1 root root 445 Apr 12 11:23 nginx-debug.service
-rw-r--r--. 1 root root 454 Apr 12 11:23 nginx.service
3. 使用yum安装Nginx,都会自动生成nginx.service,更改文件的权限
[root@localhost system]# chmod 745 nginx.service
[root@localhost system]# !ls
ls -l nginx*
-rw-r--r--. 1 root root 445 Apr 12 11:23 nginx-debug.service
-rwxr--r-x. 1 root root 454 Apr 12 11:23 nginx.service
4. 使用systemctl命令设置开机启动Nginx服务
[root@localhost system]# systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost system]#



分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP