centos直接yum安装nginx

本文提供了一种在CentOS 6.x上安装Nginx的方法,首先需要更新源,然后通过yum命令进行安装。安装完成后,启动Nginx服务,并在浏览器中测试是否成功。

Ubuntu下安装nginx,直接apt-get install nginx就行了,很方便。

但是今天装了CentOS6.2,直接yum install nginx不行,要先处理下源,下面是安装完整流程,也十分简单:

1、CentOS 6,先执行:
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
2,查看yum的nginx信息

[]# yum info nginx

Loaded plugins: fastestmirror

Determining fastest mirrors

* base: mirror.esocc.com

* extras: mirror.esocc.com

* updates: mirror.esocc.com

base                                                     | 3.7 kB     00:00

base/primary_db                                          | 4.4 MB     00:28

extras                                                   | 3.5 kB     00:00

extras/primary_db                                        |  19 kB     00:00

nginx                                                    | 2.9 kB     00:00

nginx/primary_db                                         |  22 kB     00:00

updates                                                  | 3.5 kB     00:00

updates/primary_db                                       | 2.1 MB     00:10

Installed Packages

Name        : nginx

Arch        : x86_64

Version     : 1.4.0

Release     : 1.el6.ngx

Size        : 874 k

Repo        : installed

From repo   : nginx

Summary     : nginx is a high performance web server

URL         : http://nginx.org/

 

License     : 2-clause BSD-like license

Description : nginx [engine x] is an HTTP and reverse proxy server, as well as

: a mail proxy server

3,安装并启动nignx
[root@server ~]# yum install nginx
[root@server ~]# service nginx start
Starting nginx:                                            [  OK  ]

4,然后进入浏览器,输入http://192.168.0.161/测试,如果看到

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

恭喜你,你成功了!

如果不能连接到nginx,原因很多,但是可以先检查 1,nginx服务是否真的起来了;2,linux服务器防火墙是否打开

本文来自 http://www.ttsofts.com/archives/191

转载于:https://www.cnblogs.com/ttsofts/p/4966973.html

### 在 CentOS 7 上通过 yum 安装 Nginx 并正确启动服务 #### 添加 NginxYUM 源 默认情况下,CentOS 7 的官方仓库并不包含 Nginx 软件包。为了能够通过 `yum` 命令安装 Nginx,需要先添加 Nginx 的官方源或者使用第三方镜像源(如阿里云)。以下是两种常见的方法: 1. **添加 Nginx 官方源** 使用以下命令来添加 Nginx 的官方 YUM 源: ```bash sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm ``` 这一步完成后,可以通过以下命令验证源是否成功添加: ```bash yum search nginx ``` 2. **替换为阿里云的 YUM 源** 如果希望加快软件包下载速度,可以选择更换成阿里云的 YUM 源。具体操作如下: - 备份原始的 YUM 配置文件: ```bash sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak ``` - 下载阿里云的 YUM 配置文件到指定目录: ```bash sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` - 清除旧的缓存并生成新缓存: ```bash sudo yum clean all && sudo yum makecache ``` #### 安装 Nginx 完成上述任意一种方式后,即可执行以下命令安装 Nginx: ```bash sudo yum install -y nginx ``` #### 启动 Nginx 服务 安装完成后,按照以下步骤启动 Nginx 服务并设置开机自启。 1. **启动 Nginx 服务** 执行以下命令以启动 Nginx 服务: ```bash sudo systemctl start nginx ``` 2. **设置开机自启** 让 Nginx 在系统重启后自动运行: ```bash sudo systemctl enable nginx ``` 3. **检查 Nginx 状态** 可以通过以下命令确认 Nginx 是否正常运行: ```bash sudo systemctl status nginx ``` 4. **访问测试** 打开浏览器,在地址栏输入服务器 IP 地址或域名,默认会显示 Nginx 的欢迎页面,表示配置成功[^1]。 --- ### 注意事项 - 若防火墙处于启用状态,则需开放 HTTP 和 HTTPS 协议对应的端口(80 和 443),可通过以下命令实现: ```bash sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload ``` - SELinux 设置可能会影响某些功能的行为。如果遇到问题,可临时关闭 SELinux 测试: ```bash setenforce 0 ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值