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.rpm
2.查看nginx信息
[root@localhost ~]# yum info nginx
3.使用yum安装ngnix
[root@localhost ~]# yum install nginx
效果如下:
[root@localhost ~]# yum install nginx
已加载插件:fastestmirror, langpacks
Loading 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:
验证中 : 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 start
5.查看nginx版本
[root@localhost ~]# nginx -v
6.访问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/
总用量 32
drwxr-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.types
lrwxrwxrwx. 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-utf
8.实践:
目的:修改服务名,接着从外部访问这个服务
操作:
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.com
d.你发现访问不了,原因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.gz
2.复制包到你的安装目录
[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.1
4.启动nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx
5.查看版本s
[root@localhost ~]# nginx -v
6.url访问nginx localhost或127.0.0.1
</div>
centos7安装nginx的两种方法的更多相关文章
- Centos6、7下安装Nginx的两种方法
一,通过yum命令安装 1.操作系统版本的确认很重要,因为下一步我们要依靠这个来创建yum源文件 2.创建 nginx.repo vi /etc/yum.repos.d/nginx.repo 文件内容 ...
- BayaiM__Linux安装MySQL的两种方法
BayaiM__Linux安装MySQL的两种方法 < 以下内容,纯属抄袭,如有雷同,爱咋咋地 > 阅读(21210) | 评论(4340) | 转发(5660) | 删除 编辑 ...
- Sumblime Text2安装Package Control两种方法+安装插件+注册码
刚开始不认识sumblime的时候,就直接在网上下载了一个最新版的sumblime text3,只是在配合使用go语言时,出现了一些不为自己知道的奇葩问题,于是果断把3卸载了,改成了sumblime ...
- Linux安装MySQL的两种方法
转载:http://blog.csdn.net/superchanon/article/details/8546254/ 1. 运行平台:CentOS 6.3 x86_64,基本等同于RH ...
- Centos7破解密码的两种方法--技术流ken
Centos7忘记密码 在工作或者自己练习的时候我们难免会大意忘掉自己的root密码,有些同学忘掉密码竟然第一选择是重装系统,工作中可万万使不得! 本篇博客将讲解两种最常用的破解centos7忘掉 ...
- CentOS7安装EPEL的两种方式
转自:http://www.mamicode.com/info-detail-1671603.html epel是社区强烈打造的免费开源发行软件包版本库. EPEL,即Extra Packages f ...
- linux服务器上安装jdk8的两种方法
这里介绍两种安装方式: yum安装(力荐) 从官网下载包安装 获得一台linux服务器 要在linux下安装jdk,首先你得先有一台linux服务器,虚拟机或者租一台都可以 yum安装jdk 在l ...
- Mac安装wget的两种方法
第一种.传统的安装包 A - 从ftp://ftp.gnu.org/gnu/wget/下载到最新的wget安装包到本地 B - 然后通过终端tar -zxvf命令解压到我们某个目录 C - 然后依 ...
- CentOS7安装Redis的两种方式
1. 源码安装方式(不推荐): https://www.cnblogs.com/zuidongfeng/p/8032505.html https://www.cnblogs.com/zerotomax ...
随机推荐
- Direct2D开发:向 MFC 项目添加 Direct2D 对象
0X01 创建 MFC 应用程序: 在“文件”菜单上指向“新建”,然后单击“项目”. 在“新建项目”对话框左窗格的“已安装的模板”下,展开“Visual C++”,然后选择“MFC”. 在中间窗格中, ...
- 【2017"百度之星"程序设计大赛 - 初赛(B)】Chess
[链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=776&pid=1001 [题意] 在这里写题意 [题 ...
- Vue 学习记录<1>
1.环境搭建:(前提node.js搭建) # 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue i ...
- 【软件project】机房收费系统之图形回想
[背景]通过一阶段的学习.自己整理了整理机房收费系统.以下想通过几张图来回顾一下机房的总体流程.此图形仅仅代表鄙人现阶段的理解.本文仅供參考,若有不妥的地方,请积极指正. 1.机房收费系统业务流程图 ...
- HDU 2068 RPG的错排(错排公式 + 具体解释)
RPG的错排 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Flume Sink Processors官网剖析(博主推荐)
不多说,直接上干货! Flume Sources官网剖析(博主推荐) Flume Channels官网剖析(博主推荐) Flume Channel Selectors官网剖析(博主推荐) Flume ...
- C++中引用传递与指针传递区别
C++中引用传递与指针传递区别 在C++中,指针和引用经常用于函数的参数传递,然而,指针传递参数和引用传递参数是有本质上的不同的: 指针传递参数本质上是值传递的方式,它所传递的是一个地址值.值传递过程 ...
- html只能有一个id,并且id的值只能是一个
1.如果有相同的ID,javascript只会取第一个具有该ID的标签. 2.如果id值有两个,JS只会取到第一个,并不会像class类一样,类名并列就可以同时取到.
- 原生js大总结九
81.ES6的Symbol的作用是什么? ES6引入了一种新的原始数据类型Symbol,表示独一无二的值 82.ES6中字符串和数组新增了那些方法 字符串 1.字符串模板 ...
- 原 HttpClient 4.3超时设置
https://my.oschina.net/u/577453/blog/173724 http://blog.csdn.net/zh521zh/article/details/51994140