美文网首页linux运维程序员
CentOS 7 配置LNMP环境 | 安装Nginx

CentOS 7 配置LNMP环境 | 安装Nginx

作者: 爱生活的技术君 | 来源:发表于2020-04-17 12:53 被阅读0次

1.在/etc/yum.repos.d/路径下创建nginx.repo文件夹

vim /etc/yum.repos.d/nginx.repo

2.按 “i” 切换至编辑模式,写入以下内容

[nginx] 
name = nginx repo 
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ 
gpgcheck = 0 
enabled = 1

输入后按 “Esc”,输入 “:wq”,保存文件并返回

3.安装Nginx

执行yum install -y nginx命令进行安装

4.修改配置文件

执行vim /etc/nginx/nginx.conf打开nginx.conf
找到 server{...},并将 server 大括号中相应的配置信息替换为如下内容

server {
    listen       80;
    root   /usr/share/nginx/html;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    #
    location / {
        index index.php index.html index.htm;
    }
    #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 {
        root   /usr/share/nginx/html;
    }
    #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

若 nginx.conf 文件中未找到 server{...},请在 include /etc/nginx/conf.d/*conf;上方进行添加。如下图所示:


nginx.conf

配置内容为取消对 IPv6 地址的监听,同时配置 Nginx实现与 PHP 的联动

5.启动Nginx

保存配置文件后,执行systemctl start nginx启动Nginx
执行systemctl enable nginx设置为开机自启动
此时在浏览器中访问公网IP,浏览器中显示下图表示Nginx安装配置成功

Nginx启动

相关文章

网友评论

    本文标题:CentOS 7 配置LNMP环境 | 安装Nginx

    本文链接:https://www.haomeiwen.com/subject/zeuevhtx.html