centOS 7 nginx 安装

yum安装1

添加nginx源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装

yum install -y nginx

启动

systemctl start nginx

目录

可用 whereis nginx 查找

可从/etc/nginx/nginx.conf 查看 文件目录

默认 :
/etc/nginx #配置文件
/var/log/nginx/error.log
/var/log/nginx/access.log

##########################安装完毕!##########################

yum安装2

安装 gcc

yum install -y gcc-c++

pcre pcre-devel 安装

yum install -y pcre pcre-devel

zlib 安装

yum install -y zlib zlib-devel

openssl 安装

yum -y install openssl openssl-devel

安装nginx软件

下载地址

http://nginx.org/en/download.html

进入安装目录

cd /usr/local

解压

tar -zxvf nginx-1.17.1.tar.gz

进入解压后目录

cd nginx-1.17.1

配置

./configure --prefix=/usr/local/nginx

编译安装

make && make install

验证

/usr/local/nginx/sbin/nginx -V

启动

/usr/local/nginx/sbin/nginx

重启

/usr/local/nginx/sbin/nginx -s reload

##########################安装完毕!##########################

手动安装

软件:nginx-1.17.1.tar.gz
其他所需软件:openssl-1.1.1c.tar.gz、pcre-8.43.tar.gz、zlib-1.2.11.tar.gz,perl-5.30.0.tar.gz
安装方式:源码编译安装

1.安装g++、gcc

yum install -y gcc gcc-c++

2.安装openssl软件

下载地址

 http://www.openssl.org/

进入安装目录

cd /usr/local/

解压
tar -zxvf openssl-1.1.1c.tar.gz

进入源码目录
cd openssl-1.1.1c

配置

./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/conf

如果有如下提示需要安装 perl
在这里插入图片描述
下载地址

 https://www.perl.org/

解压

tar -zxvf perl-5.30.0.tar.gz

进入解压目录

cd perl-5.30.0

配置perl安装目录

./Configure -des -Dprefix=/usr/local/perl

编译并安装

make && make install (可使用 make && make test 编译检测后在安装)

查看版本

perl -v

重新配置openssl

配置

./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/conf

编译安装

make && make install

检验安装

openssl version -a

3.安装pcre软件

下载地址

 http://www.pcre.org/

进入安装目录

cd /usr/local/

解压

tar -zxv -f pcre-8.43.tar.gz

进入源码目录

cd pcre-8.43

执行配置

./configure --prefix=/usr/local/pcre/

编译安装

make && make install

4.安装zlib软件

下载地址

 http://www.zlib.net/

进入安装目录

cd /usr/local/

解压

tar -zxv -f zlib-1.2.11.tar.gz

进入源码目录

cd zlib-1.2.11

配置

./configure --prefix=/usr/local/zlib/

编译安装

make && make install

5. 安装nginx软件

下载地址

http://nginx.org/en/download.html

进入安装目录

cd /usr/local

解压

tar -zxvf nginx-1.17.1.tar.gz

进入安装目录

cd nginx-1.17.1

配置(使用openssl、pcre、zlib的源码路径)

./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-openssl=/usr/local/openssl-1.1.1c \
--with-pcre=/usr/local/pcre-8.43 \
--with-zlib=/usr/local/zlib-1.2.11 \
--with-http_stub_status_module \
--with-threads

编译安装

make && make install

验证

/usr/local/nginx/sbin/nginx -V

##########################安装完毕!##########################

docker-compose安装

version: '3'
services:
  nginx:
    restart: always
    image: nginx
    ports:
    - 80:80
    - 443:443
    volumes:
    - ./conf.d:/etc/nginx/conf.d    #挂载配置文件目录
    - ./log:/var/log/nginx             #挂载日志目录
    - ./www:/var/www                  #资源映射挂载

配置举例:
默认会扫描 /etc/nginx/conf.d 配置下所有 .conf 文件 (即主机 挂载的./conf.d 目录下)
例:80port.conf
在这里插入图片描述

server {
        listen       80;
        server_name  localhost;
        #代理配置
        location / {
            proxy_pass http://192.168.100.181:8081; # 本地项目地址
            proxy_connect_timeout 600;
            proxy_read_timeout 600;
        }

       #静态资源映射
       location /static/ {
            root /var/www;
        autoindex on;
        }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值