CentOS 7安装nginx

参考网上其他文章做的

安装Nginx

我们从nginx官方的RPM源来安装一个预构建的稳定版本的nginx包。

rpm --import http://nginx.org/keys/nginx_signing.key
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx

这样,nginx就安装上了,安装完成后,nginx不会自动启动。现在需要做的是让nginx自动启动,另外还要做些配置让其可以随着操作系统启动而启动。我们也需要在防火墙里打开TCP/80端口,以使得可以远程访问nginx的web服务。所有这些操作、设置都只需要输入如下命令就可实现。

systemctl start nginx
systemctl enable nginx
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

Nginx已经启动了,现在来测试nginx。nginx在CentOS7下的默认文档要目录是 /usr/share/nginx/html。默认的 index.html 文件一定已经在这目录下了。让我们检测下是否可以访问到这个测试 web 页,输入 http://nginx的ip地址/访问。

启动 PHP-FPM

systemctl start php-fpm
systemctl enable php-fpm

配置LEMP,让Nginx支持PHP

首先,禁用随PHP包安装的httpd服务。

systemctl disable httpd

接下来,配置nginx虚拟主机,使得nginx可以通过PHP-FPM来处理PHP的任务。用文本编辑器打开/etc/nginx/conf.d/default.conf,然后按如下所示修改。

server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm; #charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main; location / {
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404; #这个空格特别重要
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

然后,配置PHP, 修改/etc/php.ini。

cgi.fix_pathinfo=0 # 有的文章该值为1,我试了不行
date.timezone = PRC

最后,测试nginx是否能处理PHP页面。在测试之前,请确保重启nginx和PHP-FPM。

systemctl restart nginx
systemctl restart php-fpm

创建一个叫名叫test.php的文件,然后写入如下内容,并放入/usr/share/nginx/html/目录。

<?php
phpinfo();
?>

打开浏览器,输入 http://IP地址/test.php

即可看到php的相关信息

CentOS 7安装nginx的更多相关文章

  1. 删:Centos 7安装Nginx 1.8

    [CentOS 7] 安装nginx! 首先进行 nginx yum Nginx安装记录 注意:如果用源码安装,nginx配置时需要指定--with-pcer对应的压缩包路径,如果使用二进制安装不需要 ...

  2. linux/centos下安装nginx(rpm安装和源码安装)详细步骤

    Centos下安装nginx rpm包                                                                                 ...

  3. CentOS下安装Nginx并添加nginx_upload_module

    安装前,最好能保证依赖的系统软件已经升级.    yum update CentOS上安装Nginx,如果只是简单安装,不附加其他第三方模块,一句话可以搞定:    yum install nginx ...

  4. CentOS 7 安装 Nginx 配置反向代理

    Linux使用Nginx Yum存储库上安装Nginx,适用于Red Hat Enterprise Linux和CentOS系统. 1.添加设置Nginx Yum存储库 在CentOS中首次安装Ngi ...

  5. Centos 在线安装 nginx

    centos 在线安装 nginx 安装nginx ​ 参考文档: http://nginx.org/en/linux_packages.html 中的RHEL/CentOS章节,按照步骤安装repo ...

  6. CentOS 下 安装 nginx 执行配置命令 ./configure 报错

    CentOS 下 安装 nginx 执行配置命令 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx 时提示以下错误: checkin ...

  7. 从零开始学 Java - CentOS 下安装 Nginx

    早上下起了暴雨 闹钟还未响起就听到雨滴哗啦啦击打窗户的声音,被吵醒了.起床上班,在楼下的十字路口,暴雨大到完全看不清对面,两个穿着雨衣的交警站在路口中间指挥着过往的车辆,大家都慌慌张张.急急忙忙的打着 ...

  8. Linux(Centos)之安装Nginx及注意事项

    1.Nginx的简单说明 a.  Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,期初开发的目的就是为了代理电子邮件服务器室友:Igor Sysoev开发 ...

  9. Centos下安装nginx rpm包

    1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/download.html wget http://nginx.org/packages/centos/6 ...

随机推荐

  1. postal邮件发送(二):Email headers,附件,图片介绍

    接上篇 http://www.cnblogs.com/mybky/p/5690567.html 1.邮件headers 除此之外,还有Reply-To,用于回复邮箱 2.邮件带有图片 邮件发送图片,p ...

  2. 用mysql dump 导入与导出的方法

    用mysql dump 导入与导出的方法 分类: 数据库2009-12-08 00:04 6825人阅读 评论(0) 收藏 举报 mysql数据库deleteinsertinternetdatabas ...

  3. SQL数据库面试题

    SQL数据库面试题 1.SQL SREVER中,向一个表中插入了新数据,如何快捷的得到自增量字段的当前值 这种情况其实我们经常用到,比如我们新建了一个用户,建立完用户后我们希望马上得到这个新用户的ID ...

  4. 控制台命令行API

    js调试系列: 控制台命令行API   上次初步介绍了什么是控制台<js调试系列: 初识控制台>,以及简单的 console.log 输出信息.最后还有两个小问题,我们就当回顾,来看下怎么 ...

  5. 推荐几个JSON工具

    JSON查看 http://jsonviewer.codeplex.com/ JSON转类(非常好使) http://jsonclassgenerator.codeplex.com https://g ...

  6. WCF入门教程(图文)VS2012

    WCF入门教程(图文)VS2012 上一遍到现在已经有一段时间了,先向关注本文的各位“挨踢”同仁们道歉了.小生自认为一个ITer如果想要做的更好,就需要将自己的所学.所用积极分享出来,接收大家的指导和 ...

  7. 浅谈PHP在各系统平台下的换行符

    <?php echo 'aaa\n';//用于linux.unix平台C的换行也是如此 echo 'bbb\r';//用于mac平台 echo 'ccc\r\n';//用于windows平台 / ...

  8. Definition of:payload

    (1) Refers to the "actual data" in a packet or file minus all headers attached for transpo ...

  9. Leetcode::Pathsum & Pathsum II

    Pathsum Description: Given a binary tree and a sum, determine if the tree has a root-to-leaf path su ...

  10. 网络负载均衡环境下wsHttpBinding+Message Security+Windows Authentication的常见异常

    提高Windows Communication Foundation (WCF) 应用程序负载能力的方法之一就是通过把它们部署到负载均衡的服务器场中. 其中可以使用标准的负载均衡技术, Windows ...