美文网首页
Linux 安装 Nginx

Linux 安装 Nginx

作者: xuanxiao | 来源:发表于2018-03-06 21:38 被阅读0次

一、环境确认

    1、确认网络可用

        登录服务器后执行:ping www.baidu.com

出现以上即可

    2、确认yum可用

        yum list|grep nginx

出现以上即可

    3、确认关闭iptables规则

        查看是否开启

            iptables -L

        关闭

        iptables -F

        iptables -t nat -F

        Centos7永久关闭防火墙

        启动一个服务:systemctl start firewalld.service

        关闭一个服务:systemctl stop firewalld.service

        重启一个服务:systemctl restart firewalld.service

        显示一个服务的状态:systemctl status firewalld.service

        在开机时启用一个服务:systemctl enable firewalld.service

        在开机时禁用一个服务:systemctl disable firewalld.service

        查看服务是否开机启动:systemctl is-enabled firewalld.service

        查看已启动的服务列表:systemctl list-unit-files|grep enabled

    4、确认停用selinux

        查看

            getenforce

        关闭

            setenforce 0

        永久关闭方法

            vim /etc/sysconfig/selinux

                reboot

                    重启后即永久关闭

 5、安装对应的工具

        yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake

        yum -y install wget httpd-tools vim

    6、创建对应的目录

        cd /opt

        mkdir app download logs work backup

        app:存放代码     download:存放下载的代码或程序包    logs:日志

    7、安装Nginx

        打开官网:http://nginx.org/

Pre-Built Packages for Stable version

To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/

gpgcheck=0

enabled=1

Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.

For Debian/Ubuntu, in order to authenticate the nginx repository signature and to eliminate warnings about missing PGP key during installation of the nginx package, it is necessary to add the key used to sign the nginx packages and repository to the apt program keyring. Please downloadthis key from our web site, and add it to the apt program keyring with the following command:

sudo apt-key add nginx_signing.key

For Debian replace codename with Debian distribution codename, and append the following to the end of the /etc/apt/sources.list file:

deb http://nginx.org/packages/debian/codenamenginxdeb-src http://nginx.org/packages/debian/codenamenginx

For Ubuntu replace codename with Ubuntu distribution codename, and append the following to the end of the /etc/apt/sources.list file:

deb http://nginx.org/packages/ubuntu/codenamenginxdeb-src http://nginx.org/packages/ubuntu/codenamenginx

For Debian/Ubuntu then run the following commands:

apt-get update

apt-get install nginx

For SLES run the following command:

zypper addrepo -G -t yum -c 'http://nginx.org/packages/sles/12' nginx

输入命令:

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

修改好:

查看:

安装:

    yum -y install nginx

查看是否安装成功

    nginx -v

查看Nginx都安装了哪些目录

    命令:rpm -ql nginx

Nginx安装完成如果要换成/data/www的根目录

若报FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

将fastcgi_param对应的

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

换成

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

相关文章

网友评论

      本文标题:Linux 安装 Nginx

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