Linux Nginx 下载 安装 配置 使用

博文目录


环境

阿里云ECS(Aliyun Linux 2.1903 LTS 64位)

下载

http://nginx.org/en/download.html
http://nginx.org/download/nginx-1.18.0.tar.gz

选择稳定版(Stable version)下载即可, 分 linux 和 windows 两种, linux 版下载的是源码, 源码放到临时目录, 然后编译安装到指定目录

安装

tar -zxvf nginx-1.18.0.tar.gz 得到解压包, 直接在解压包内执行下面的命令, 注意安装路径需要手动创建, 不要直接装在解压后的路径内
./configure --help 获取可配置参数
./configure --prefix=/mrathena/application/nginx-1.18.0 配置安装目录, 该目录会自动创建, 执行之后会打印出配置信息
./configure --prefix=/mrathena/application/nginx-1.18.0 --with-http_ssl_module 如果需要使用 https(ssl) 的话, 需要添加该配置, 执行之后会打印出配置信息

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/mrathena/application/nginx-1.18.0"
  nginx binary file: "/mrathena/application/nginx-1.18.0/sbin/nginx"
  nginx modules path: "/mrathena/application/nginx-1.18.0/modules"
  nginx configuration prefix: "/mrathena/application/nginx-1.18.0/conf"
  nginx configuration file: "/mrathena/application/nginx-1.18.0/conf/nginx.conf"
  nginx pid file: "/mrathena/application/nginx-1.18.0/logs/nginx.pid"
  nginx error log file: "/mrathena/application/nginx-1.18.0/logs/error.log"
  nginx http access log file: "/mrathena/application/nginx-1.18.0/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

make install 编译安装, 完成后, /mrathena/application/nginx-1.18.0 目录下将出现 conf, html, logs, sbin 等目录, nginx 脚本就在 sbin 目录下
nginx 的编译需要一些依赖库, 如果缺少的话, 需要手动添加
yum –y install gcc-c++ 编译依赖gcc环境
yum install -y pcre pcre-devel 安装 pcre 库, pcre-devel是使用pcre开发的一个二次开发库
yum install -y zlib zlib-devel 安装 zlib 库, zlib库提供了很多种压缩和解压缩的方式, nginx使用zlib对http包的内容进行gzip
yum install -y openssl openssl-devel OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用

配置

nginx 默认使用 80 端口, 建议对外只暴露 nginx 和 80 端口, 用 nginx 来反向代理内部服务, 安全还方便
参数配置 nginx configuration file: "/mrathena/application/nginx-1.18.0/conf/nginx.conf"

我的应用列表

  • 8888: mrathena.jar
  • 8080: jenkins.war

我的域名: mrathena.cn, 需在阿里云域名解析配置A类解析, service和jenkins, 或者*

我的目的

server {
    listen 80;
    server_name service.mrathena.cn;
    location / {
        proxy_pass http://localhost:8888;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
server {
    listen 80;
    server_name jenkins.mrathena.cn;
    location / {
        proxy_pass http://localhost:8080;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

使用

./nginx 启动 nginx, 使用默认配置文件
./nginx -s stop 快速停止, 相当于直接 kill
./nginx -s quit 完整停止
./nginx -s reload 运行时重新加载配置文件
./nginx -t 验证当前配置文件是否正确可用

可以配置 alias 方便使用, 在 /root/.bashrc 文件内添加如下 alias, 可在任何地方直接执行 nginx.start, nginx.reload

alias cdnginx='cd /mrathena/application/nginx-1.18.0'
alias nginx.start='/mrathena/application/nginx-1.18.0/sbin/nginx'
alias nginx.stop='/mrathena/application/nginx-1.18.0/sbin/nginx -s stop'
alias nginx.quit='/mrathena/application/nginx-1.18.0/sbin/nginx -s quit'
alias nginx.reload='/mrathena/application/nginx-1.18.0/sbin/nginx -s reload'
alias nginx.check='/mrathena/application/nginx-1.18.0/sbin/nginx -t'

参考

www.cnblogs.com/xiaowazi/p/10610508.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值