Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux下安装nginx #26

Open
chenshenhai opened this issue Dec 1, 2017 · 0 comments
Open

Linux下安装nginx #26

chenshenhai opened this issue Dec 1, 2017 · 0 comments
Labels

Comments

@chenshenhai
Copy link
Owner

chenshenhai commented Dec 1, 2017

系统

CentOS

系统工具

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

安装pcre

  • 下载 pcre 包
  • 安装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 服务
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 chenshenhai changed the title Linux下配置nginx Linux下安装nginx Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant