Linux服务器安装nginx

/ nginxLinux / 没有评论 / 2148浏览
#yum install nginx  

centos-6-0 安装nginx

如果无法安装nginx看下面的方法,可以就直接跳到下方启动nginx 

#rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

使用以上命令安装nginx库在使用第一条命令安装nginx

Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.njupt.edu.cn * extras: mirrors.nju.edu.cn * updates: mirrors.nju.edu.cn Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 0:1.14.0-1.el6.ngx will be installed --> Processing Dependency: libpcre.so.0()(64bit) for package: nginx-1.14.0-1.el6.ngx.x86_64 --> Finished Dependency Resolution Error: Package: nginx-1.14.0-1.el6.ngx.x86_64 (nginx) Requires: libpcre.so.0()(64bit) You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest

如果安装出现上面的情况有2种可能:

  1. 没有网络可以试着ping www.baidu.com,看有没有网没有就没法下载了。

  2. 执行下面的命令

#sudo yum install epel-release
#sudo yum install nginx

在对提示回答yes后,结尾出现Complete!      Nginx在服务器上完成安装。

 #nginx -v  查看nginx版本
 #rpm -ql nginx  查看nginx的安装目录
 #nginx -t    测试nginx的配置
 #sudo systemctl start nginx  启动nginx

 如果防火墙在运行中,执行以下命令

 #sudo firewall-cmd --permanent --zone=public --add-service=http
 #sudo firewall-cmd --permanent --zone=public --add-service=https
 #sudo firewall-cmd --reload

如果还不行就试下面的命令放行80端口

#iptables -A INPUT -p tcp --dport 80 -j ACCEPT

如果想系统启动就运行nginx,可以执行以下命令

#sudo systemctl enable nginx

接下来在浏览器输入服务器ip访问就可以了。

CentOS 7.0 安装nginx

下载对应当前系统版本的nginx包(package)

# wget  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

建立nginx的yum仓库

# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

下载并安装nginx

# yum install nginx

启动nginx服务

systemctl start nginx

配置

默认的配置文件在 /etc/nginx 路径下,使用该配置已经可以正确地运行nginx;如需要自定义,修改其下的 nginx.conf 等文件即可。