blog icon indicating copy to clipboard operation
blog copied to clipboard

Linux下安装nginx

Open chenshenhai opened this issue 6 years ago • 0 comments

系统

CentOS

系统工具

yum -y install make gcc-c++ libtool   openssl openssl-devel  zlib zlib-devel 

安装pcre

  • 下载 pcre 包
    • 下载地址 https://sourceforge.net/projects/pcre/files/pcre/
    • 这里选择当前最新的 8.44版本
    • wget https://sourceforge.net/projects/pcre/files/pcre/8.44/pcre-8.44.tar.gz --no-check-certificate
  • 安装pcre
    • 解压 tar vzxf pcre-8.44.tar.gz
    • 进入解压后目录cd vzxf pcre-8.44
    • 执行配置./configure
    • 安装 make && make install
    • 检查安装结果 pcre-config --version
    • 复制安装结果到 制定目录 sudo cp -a pcre-8.44/ /usr/local/src/

安装nginx

  • 下载nginx
    • 下载地址 http://nginx.org/download/
    • 这里选择当前最新版本 1.17.9
    • wget http://nginx.org/download/nginx-1.17.9.tar.gz
  • 安装nginx
    • tar vzxf nginx-1.17.9.tar.gz
    • 进入解压目录 cd nginx-1.17.9
    • 配置安装 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.44
    • 注意:这里的pcre的版本目录根据自己系统安装实际情况修改
    • 安装 make && make install
    • 检查安装结果 /usr/local/nginx/sbin/nginx -v

配置nginx 全局变量

  • 进入主目录 cd ~
  • 编辑配置文件 vim .bashrc
# nginx env
export NGINX_HOME=/usr/local/nginx/sbin/
export PATH=$NGINX_HOME:$PATH
  • 保存配置 source .bashrc
  • 验证配置结果 nginx -v

使用nginx

  • nginx
  • 访问 http://127.0.0.1:80/
# 启动 nginx 服务
nginx 

# 关闭 nginx 服务
nginx -s stop

其他nginx配置

多域名共用 80 端口

server {
    listen  80;
    server_name     001.example.com;
    location / {
        proxy_pass      http://127.0.01:3001;
    }
}

server {
    listen  80;
    server_name     002.example.com;
    location / {
        proxy_pass      http://127.0.01:3002;
    }
}

chenshenhai avatar Dec 01 '17 14:12 chenshenhai