yum 安装 Nginx 以及相关配置

相关内容:
1. yum 安装 MySQL;
2. yum 安装 PHP;
3. yum 安装 Nginx 以及相关配置(本篇);
4. yum 安装 Apache 以及相关配置;

下载 Nginx 的 repo 源

cd /usr/local/src
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装 repo 源包

rpm -Uvh nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum repolist all

安装 Nginx

yum install nginx

防火墙设置,开放 80 端口

# 设置iptables
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -nL

# 设置 firewalld
firewall-cmd --permanent --zone=public -add-port=80/tcp
firewall-cmd --reload

启动 Nginx

systemctl start nginx
systemctl state nginx

# 开机启动
systemctl enable nginx.service	
ss -ltnp

协同工作

# 查询目录
vim /etc/nginx/conf.d/default.conf

# 修改 
location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

# 去掉以下代码注释并修改 fastcgi_param
location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }


# 在 /usr/share/nginx/html 目录创建测试文件
vim /usr/share/nginx/html/index.php

# 写入测试内容
<?php
phpinfo();
?>

# 重启
systemctl restart nginx

另附:LNMP 环境一键安装: http://github.com/maicong/LNMP

搞定!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值