Centos 7 Nginx的安装和配置
2018-01-15 11:26
381 查看
进入Nginx官网站 http://nginx.org/,进入后选择最新的版本,进入页面后在
Stable version中选择
nginx-*右键复制链接,然后用
wget下载
[root@iZuf6b4wamau0tcvk7hwglZ ~]# wget http://nginx.org/download/nginx-1.12.0.tar.gz[/code]
如果提示wget命令未找到,则执行[root@iZuf6b4wamau0tcvk7hwglZ ~]# sudo yum install wget
下载完用 ll 命令查看刚刚下载获得的nginx-*.tar.gz文件,用下面命令解压它[root@iZuf6b4wamau0tcvk7hwglZ ~]# tar -zxvf nginx-1.12.0.tar.gz
-z: 表示使用gzip的属性。
-x: 解开一个压缩文件的参数指令。
-v: 表示压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
-f: 使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
参考资料
安装Nginx前,需要安装以下三个依赖包:
gzip 模块需要zlib库
rewrite 模块需要pcre库
ssl 功能需要openssl库
https://www.openssl.org/source/[root@iZuf6b4wamau0tcvk7hwglZ ~]# wget https://www.openssl.org/source/openssl-fips-2.0.14.tar.gz[/code]
http://www.zlib.net/[root@iZuf6b4wamau0tcvk7hwglZ ~]# wget http://www.zlib.net/zlib-1.2.11.tar.gz[/code]
(http://www.pcre.org/)[http://www.pcre.org/[root@iZuf6b4wamau0tcvk7hwglZ ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz[/code]
下载完成后安装,依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包
1.安装openssl[root@iZuf6b4wamau0tcvk7hwglZ ~]# tar -zxvf openssl-fips-2.0.14.tar.gz [root@iZuf6b4wamau0tcvk7hwglZ ~]# cd openssl-fips-2.0.14/ [root@iZuf6b4wamau0tcvk7hwglZ openssl-fips-2.0.14]# ./config [root@iZuf6b4wamau0tcvk7hwglZ openssl-fips-2.0.14]# make [root@iZuf6b4wamau0tcvk7hwglZ openssl-fips-2.0.14]# make install
2.安装zlib[root@iZuf6b4wamau0tcvk7hwglZ ~]# tar -zxvf zlib-1.2.11.tar.gz [root@iZuf6b4wamau0tcvk7hwglZ ~]# cd zlib-1.2.11/ [root@iZuf6b4wamau0tcvk7hwglZ zlib-1.2.11]# ./configure [root@iZuf6b4wamau0tcvk7hwglZ zlib-1.2.11]# make [root@iZuf6b4wamau0tcvk7hwglZ zlib-1.2.11]# make install
安装gcc g++yum install gcc-c++
3.安装pcre[root@iZuf6b4wamau0tcvk7hwglZ ~]# tar -zxvf pcre-8.39.tar.gz [root@iZuf6b4wamau0tcvk7hwglZ ~]# cd pcre-8.39/ [root@iZuf6b4wamau0tcvk7hwglZ pcre-8.39]# ./configure [root@iZuf6b4wamau0tcvk7hwglZ pcre-8.39]# make [root@iZuf6b4wamau0tcvk7hwglZ pcre-8.39]# make install
4.安装nginx[root@iZuf6b4wamau0tcvk7hwglZ ~]# tar -zxvf nginx-1.12.0.tar.gz [root@iZuf6b4wamau0tcvk7hwglZ ~]# cd nginx-1.12.0/ [root@iZ2844brz0xZ nginx-1.12.0]# ./configure --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-fips-2.0.14 [root@iZuf6b4wamau0tcvk7hwglZ nginx-1.12.0]# make [root@iZuf6b4wamau0tcvk7hwglZ nginx-1.12.0]# make install
检测是否安装成功[root@iZuf6b4wamau0tcvk7hwglZ nginx-1.12.0]# cd /usr/local/nginx/sbin/ [root@iZuf6b4wamau0tcvk7hwglZ sbin]# ./nginx -t
若出现下方信息表示安装成功nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
最后一步:启动Nginx[root@iZuf6b4wamau0tcvk7hwglZ sbin]# ./nginx
查看端口[root@iZuf6b4wamau0tcvk7hwglZ sbin]# netstat -ntlp
出现以下结果
至此,nginx的安装完成‘配置Nginx
进入Nginx目录,编辑nginx.conf配置文件[root@iZuf6b4wamau0tcvk7hwglZ nginx]# cd /usr/local/nginx/ [root@iZuf6b4wamau0tcvk7hwglZ nginx]# cd conf/ [root@iZuf6b4wamau0tcvk7hwglZ conf]# vim nginx.conf
看到server模块下有:location / { root html; index index.html index.htm; }
这段表示所有的文件都会进入html这个目录下,我们现在编写与php相关的语句
在下面我们可以找到配置文件已经帮我们写好了我们只需要把前面的注释符号#去掉就好了location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
输入:wq保存退出
进入nginx的html目录,新建一个文件测试一下[root@iZuf6b4wamau0tcvk7hwglZ conf]# cd .. [root@iZuf6b4wamau0tcvk7hwglZ nginx]# cd html/ [root@iZuf6b4wamau0tcvk7hwglZ html]# vim test.php
输入<?php phpinfo(); ?>
忘了说,修改完配置文件记得要重新启动nginx哦[root@iZuf6b4wamau0tcvk7hwglZ ~]# cd /usr/local/nginx/sbin/ [root@iZuf6b4wamau0tcvk7hwglZ sbin]# ./nginx -s reload
在花费超多时间和精力再查阅各种博客的配置LNMP后,终于配好了。其实以前配过一次,只不过那时候配的是简陋版,并且自己也对其中过程不是很熟悉。之前配好后没有进行记录,很多大佬都有将他们的配置过程写在博客中,于是这次重新配置,并记录完毕。
说说其中的坑吧,在最后的创建test.php后,在浏览器上显示file not found,本来想询问阿里客服,了解是fpm没配好还是哪个路径没设好,当时毫无头绪。结果阿里客服推荐我去那边收费的区域合作机构帮忙配置,又只好硬着头皮再去翻翻繁多的资料,没想到最后居然配好了。(此刻刚配好的我在写这篇文章时就已经笑出了声)果然是/usr/local/nginx/conf 下的 nginx.conf 里的路径有问题。
这是之前的location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
改为location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; include fastcgi_params; }
忘了说,修改完配置文件记得要重新启动nginx哦[root@iZuf6b4wamau0tcvk7hwglZ~]# cd /usr/local/nginx/sbin/ [root@iZuf6b4wamau0tcvk7hwglZ sbin]# ./nginx -s reload
打开网址,运行成功~
参考资料
http://www.cnblogs.com/hzh19870110/p/6100661.html 作者:grhlove123
相关文章推荐
- CentOS-6.3安装配置Nginx
- centos下nginx+tomcat安装配置 nginx结合tomcat
- Centos6.5服务器环境搭建之安装Nginx以及Https访问方式的配置
- LNMP= CentOS+Nginx+MySQL+PHP 安装配置及简易建站笔记(持续更新中)
- CENTOS 6.x/7.x yum安装配置Nginx(最新版)
- Linux中Nginx安装与配置(CentOS-6.5:nginx-1.5.0)
- centos6.9源码安装nginx1.12.2并配置php7
- CentoS下Django1.3 & Nginx(FastCGI & flup) & MySQL安装配置详解
- CentOS6.5下nginx的安装与配置
- nginx在centos6.5下的安装和反向代理简单配置
- centos7系统下nginx安装并配置开机自启动操作
- Nginx在centos6.5下的安装和反向代理简单配置
- Centos7 fastdfs/nginx 安装与配置
- CentOS下的Nginx安装配置
- centos 安装配置php,nginx
- CENTOS 6.5 配置YUM安装NGINX
- CentOS 6.5 FastDFS+nginx安装配置
- CentOS6.4安装配置nginx+pcre+php/fpm
- Linux(CentOS)下,下载安装Nginx并配置
- Linux(CentOS)下,下载安装Nginx并配置