centos7 安装nginx与配置
第一步安装
使用Yum安装是推荐的方式,整体的流程非常的简单,也不容易出错,如果不需要什么特殊配置,建议使用Yum尽进行安装。
第一种安装方式,通过添加epel源
yum install epel-release
yum update
yum install nginx
什么是epel
如果既想获得 RHEL 的高质量、高性能、高可靠性,又需要方便易用(关键是免费)的软件包更新功能,那么 Fedora Project 推出的 EPEL(Extra Packages for Enterprise Linux)正好适合你。EPEL(http://fedoraproject.org/wiki/EPEL) 是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。
update会花费很多时间
第二种添加nginx源到yum中
.将nginx放到yum repro库中
[root@localhost ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm .查看nginx信息
[root@localhost ~]# yum info nginx .使用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-.el7.ngx 将被 安装
······
······
正在安装 : :nginx-1.10.-.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/ ----------------------------------------------------------------------
验证中 : :nginx-1.10.-.el7.ngx.x86_64 / 已安装:
nginx.x86_64 :1.10.-.el7.ngx
完毕! .启动nginx
[root@localhost ~]# service nginx start .查看nginx版本
[root@localhost ~]# nginx -v .访问nginx,现在你可以通过公网ip (本地可以通过 localhost /或 127.0.0.1 ) 查看nginx 服务返回的信息。
[root@localhost ~]# curl -i localhost
效果如下:
······
Welcome to nginx!。
······
.nginx配置文件位置在/etc/nginx/
[root@localhost /]# ll /etc/nginx/
总用量
drwxr-xr-x. root root 10月 : conf.d
-rw-r--r--. root root 5月 : fastcgi_params
-rw-r--r--. root root 5月 : koi-utf
-rw-r--r--. root root 5月 : koi-win
-rw-r--r--. root root 5月 : mime.types
lrwxrwxrwx. root root 10月 : modules -> ../../usr/lib64/nginx/modules
-rw-r--r--. root root 5月 : nginx.conf
-rw-r--r--. root root 5月 : scgi_params
-rw-r--r--. root root 5月 : uwsgi_params
-rw-r--r--. root root 5月 : win-utf .实践:
目的:修改服务名,接着从外部访问这个服务
操作:
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
步骤二:关闭防火墙,具体下文有说明 .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
可能会遇到的问题
具体情况如下 。本机能ping通虚拟机 。虚拟机也能ping通本机 。虚拟机能访问自己的web 。本机无法访问虚拟己的web 这个问题的原因是服务器的80端口没有打开或防火墙没有关闭
解决方法
如果是centos6:
解决方法如下:
/sbin/iptables -I INPUT -p tcp --dport -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 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
第二种安装方法
.下载nginx包。
[root@localhost ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz .复制包到你的安装目录
[root@localhost ~]# cp nginx-1.10..tar.gz /usr/local/ .解压
[root@localhost ~]# tar -zxvf nginx-1.10..tar.gz
[root@localhost ~]# cd nginx-1.10. .启动nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx .查看版本s
[root@localhost ~]# nginx -v .url访问nginx localhost或127.0.0.
参考自http://www.centoscn.com/nginx/2017/0119/8422.html
二、配置
用以上方法安装的nginx的配置文件在/etc/nginx
备份下nginx.conf
cp nginx.conf nginx.conf.backup
编辑vim nginx.conf
location / {
proxy_pass http://127.0.0.1:5000;
}
以上配置是用的nginx的反向代理功能,将80端口转发到5000端口,可以根据需要修改
centos7 安装nginx与配置的更多相关文章
- 【Nginx安装】CentOS7安装Nginx及配置
[Nginx安装]CentOS7安装Nginx及配置 2018年03月05日 11:07:21 阅读数:7073 Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttp ...
- CentOS7安装Nginx及配置
Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttpd具有占有内存少,稳定性高等优势.**它最常的用途是提供反向代理服务.** 安装 在Centos下,yum源不 ...
- centos7安装nginx并配置前端环境
服务器环境:CentOS Linux release 7.5.1804 (Core) 安装路径:/usr/local 1.安装编译工具以及库文件 (新服务器,未安装则需要先安装) # yum -y i ...
- centos7安装nginx并配置web前端环境。
1.安装nginx -sudo yum install nginx 2.启动nginx - systemctl start nginx 3.修改nginx路径配置,/etc/nginx/nginx.c ...
- linux(centos7) 安装nginx
linux(centos7) 安装nginx 1.14(stable) 版本 Nginx配置文件常见结构的从外到内依次是「http」「server」「location」等等,缺省的继承关系是从外到内, ...
- VMware虚拟机中的CentOS7安装Nginx后本机无法访问的解决办法
VMware虚拟机中的CentOS7安装Nginx后本机无法访问的解决办法 在linux上安装nginx 请参考:Linux Centos7 安装 nginx 在虚拟机centos7上安装nginx之 ...
- 【转】linux 编译安装nginx,配置自启动脚本
linux 编译安装nginx,配置自启动脚本 本文章来给各位同学介绍一篇关于linux 编译安装nginx,配置自启动脚本教程,希望有需要了解的朋友可一起来学习学习哦. 在公司的suse服务器装ng ...
- linux 编译安装nginx,配置自启动脚本
本文章来给各位同学介绍一篇关于linux 编译安装nginx,配置自启动脚本教程,希望有需要了解的朋友可一起来学习学习哦. 在公司的suse服务器装nginx,记录下安装过程: 参照这篇文章:Linu ...
- Centos7安装RocketMQ及配置测试
环境 Centos7 RocketMQ 3.2.6 安装位置 /usr/local/alibaba-rockermq 外网ip 182.254.145.66 内网ip 10.105.23.114 安装 ...
随机推荐
- 为什么VS没有提供平win64程序编写项
最近在学习C++和MFC编程,突然有个疑问,为什么每次新建项目时,都只有win32 console application,从来没见过win64的选项,于是去网上查了查,下面是我找到的几个答案: 作者 ...
- 【MT8382/8121】使用绝对路径编译模块会导致recourse_overlay无法应用的问题
之前为了方便mm模块编译,写了个脚本,实现了在任意模块其子目录下执行脚本即可编译的功能. 其实原理就是一层一层目录地往上寻找Android.mk文件,找到存放Android.mk目录后,就把该目录当作 ...
- strace 命令是一种强大的工具,它能够显示所有由用户空间程序发出的系统调用。
strace 命令是一种强大的工具,它能够显示所有由用户空间程序发出的系统调用. http://bbs.51cto.com/thread-1106891-1.html
- mysql分页查询语法
一.limit语法 SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset LIMIT 子句可以被用于强制 SELECT 语句返回指 ...
- MySQL 基础内容
创建数据库 对于表的操作需要先进入库 use 库名: -- 创建一个名为 inana_db 的数据库,数据库字符编码指定为 utf8create database inana_db character ...
- python tips:列表推导
看一个代码: a=[1,2,3,4,5,6,7,8,9] b=[5 if (i >3) else 1 for i in a] print(b) 这就是列表推导. 列表推导一般用在通过一个list ...
- MATLAB求解方程与方程组
1. solve函数 ①求解单个一元方程的数值解 syms x; x0 = double(solve(x +2 - exp(x),x)); 求x+2 = exp(x)的解,结果用double ...
- 【转】Ubuntu 14.04.3上配置并成功编译Android 6.0 r1源码
http://www.linuxidc.com/Linux/2016-01/127292.htm 终于成功把Android 6.0 r1源码的源码编译.先上图,这是在Ubuntu中运行的Android ...
- Redis 源码走读(一)事件驱动机制与命令处理
eventloop 从 server.c 的 main 方法看起 int main(int argc, char **argv) { ....... aeSetBeforeSleepProc(serv ...
- 《javascript高级程序设计》读书小延伸
这本书已经读了几章了,想着试试能不能做出点东西,就简单的练了把手.觉得对于初学者,自己试着练练,效果还不错的. 挥刀要从轻的开始,起初的原因是和同事谈起曾经的逝水年华(小时候干的坏事)时说起了曾经的一 ...