• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >Linux > centos7安装nginx的两种方法

centos7安装nginx的两种方法

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含centos7 nginx安装,centos7 yum安装nginx,centos7编译安装nginx,centos7-lvs nginx,centos7 yum nginx等服务器相关知识,网友希望可以进行参考

centos7安装nginx的两种方法


centos7安装nginx

第一种方式:通过yum安装

直接通过 yum install nginx 肯定是不行的,因为yum没有nginx,所以首先把 nginx 的源加入 yum 中。

运行下面的命令:

1.将nginx放到yum repro库中[root@localhost ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm2.查看nginx信息[root@localhost ~]# yum info nginx3.使用yum安装ngnix[root@localhost ~]# yum install nginx效果如下:[root@localhost ~]# yum install nginx已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.usc.edu * extras: mirror.raystedman.net * updates: mirror.metrocast.net正在解决依赖关系--> 正在检查事务---> 软件包 nginx.x86_64.1.1.10.1-1.el7.ngx 将被 安装      ······      ······正在安装    : 1:nginx-1.10.1-1.el7.ngx.x86_64        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/----------------------------------------------------------------------  验证中      : 1:nginx-1.10.1-1.el7.ngx.x86_64                                                                                 1/1 已安装:  nginx.x86_64 1:1.10.1-1.el7.ngx                                                                                     完毕!4.启动nginx[root@localhost ~]# service nginx start5.查看nginx版本[root@localhost ~]# nginx -v6.访问nginx,现在你可以通过公网ip (本地可以通过 localhost /或 127.0.0.1 ) 查看nginx 服务返回的信息。[root@localhost ~]# curl -i localhost效果如下:      ······Welcome to nginx!。      ······7.nginx配置文件位置在/etc/nginx/[root@localhost /]# ll /etc/nginx/总用量 32drwxr-xr-x. 2 root root   25 10月 12 13:11 conf.d-rw-r--r--. 1 root root 1007 5月  31 22:09 fastcgi_params-rw-r--r--. 1 root root 2837 5月  31 22:09 koi-utf-rw-r--r--. 1 root root 2223 5月  31 22:09 koi-win-rw-r--r--. 1 root root 3957 5月  31 22:09 mime.typeslrwxrwxrwx. 1 root root   29 10月 12 13:11 modules -> ../../usr/lib64/nginx/modules-rw-r--r--. 1 root root  643 5月  31 22:08 nginx.conf-rw-r--r--. 1 root root  636 5月  31 22:09 scgi_params-rw-r--r--. 1 root root  664 5月  31 22:09 uwsgi_params-rw-r--r--. 1 root root 3610 5月  31 22:09 win-utf8.实践:目的:修改服务名,接着从外部访问这个服务操作:a.修改nginx配置文件[root@localhost nginx]# vim /etc/nginx/conf.d/default.conf修改server_name部分:server_name  yytest.com;b.重载服务[root@localhost nginx]# /usr/sbin/nginx -s reload c.从外部访问nginx服务(192.168.10.11)如在客户机(192.168.10.10)的浏览器访问:http://yytest.comd.你发现访问不了,原因1,你没有在hosts文件做映射;原因2,及时你在hosts文件中了映射,由于nginx服务器的80端口堵塞或防火墙没关e.解决办法:步骤一:修改客户机(192.168.10.10)的hosts文件,使用SwitchHosts工具添加 192.168.10.11     yytest.com步骤二:关闭防火墙,具体下文有说明9.nginx常用操作启动:$ /usr/sbin/nginx或任意路径下运行service nginx start(centos7是systemctl start nginx.service )重启:$ /usr/sbin/nginx –s reload停止:$ /usr/sbin/nginx –s stop测试配置文件是否正常:$ /usr/sbin/nginx –t

可能遇到的问题:

具体情况如下 1。本机能ping通虚拟机 2。虚拟机也能ping通本机 3。虚拟机能访问自己的web 4。本机无法访问虚拟己的web 这个问题的原因是服务器的80端口没有打开或防火墙没有关闭

解决办法

如果是centos6:解决方法如下: /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 然后保存: /etc/rc.d/init.d/iptables save 重启防火墙 /etc/init.d/iptables restart CentOS防火墙的关闭,关闭其服务即可: 查看CentOS防火墙信息:/etc/init.d/iptables status 关闭CentOS防火墙服务:/etc/init.d/iptables stop 永久关闭防火墙: chkconfig –level 35 iptables off如果是centos7[root@rhel7 ~]# systemctl status firewalld.service[root@rhel7 ~]# systemctl stop firewalld.service[root@rhel7 ~]# systemctl disable firewalld.service[root@rhel7 ~]# systemctl status firewalld.service

扩展知识:

启动一个服务:systemctl start firewalld.service关闭一个服务:systemctl stop firewalld.service重启一个服务:systemctl restart firewalld.service显示一个服务的状态:systemctl status firewalld.service在开机时启用一个服务:systemctl enable firewalld.service在开机时禁用一个服务:systemctl disable firewalld.service查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?查看已启动的服务列表:systemctl list-unit-files|grep enabled

第二种方式:通过手动下载安装包解压安装

1.下载nginx包。[root@localhost ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz2.复制包到你的安装目录[root@localhost ~]# cp nginx-1.10.1.tar.gz /usr/local/3.解压[root@localhost ~]# tar -zxvf nginx-1.10.1.tar.gz[root@localhost ~]# cd nginx-1.10.14.启动nginx[root@localhost ~]# /usr/local/nginx/sbin/nginx5.查看版本s[root@localhost ~]# nginx -v6.url访问nginx localhost或127.0.0.1

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • centos7安装nginx的两种方法

相关文章

  • CentOS上安装MongoDB 3.2
  • Linux lsof命令使用详解
  • ubuntu修改terminal终端的主机名的实现方法
  • centos配置samba服务器
  • CentOS云主机中Nginx正向代理同时支持 https 和 http 访问
  • CentOS7下安装MySQL5.7安装与配置(YUM)
  • CentOS下安装redis和redis集群
  • 使用 Linux seq 命令生成数字序列(推荐)
  • Centos7.2安装Nginx实现负载平衡
  • HTTP返回状态码中301和302的区别

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • centos7配置YUM安装DNS服务
    • Ubuntu启用VNC服务的配置
    • Centos6.5下彻底删除MYSQL
    • Asp.Net Core 发布和部署( MacOS + Linux + Nginx )
    • CentOS源码安装MySQL 5.6.16
    • CentOS中搭建Gogs服务器
    • 基于Centos7 部署Varnish缓存代理服务器
    • centos7部署LAMP+xcache
    • CentOS服务器系统下更改Apache默认网站目录
    • Centos一键部署openstack RDO packstack

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有