【Nginx 1.20.1 基础】Nginx 在 MacOS 编译构建部署启动测试 2021_9_14

互联网 2021/9/15 7:08:13

Nginx 在 MacOS 编译构建部署启动测试 引用命令预先准备执行中级测试引用中级测试部分 1.nginx通过自定义header属性来转发不同的服务 构建部分 2.Nginx官网 3.Nignx构建官方文档 4.PCRE Download页面 5.Zlib官网 & Download页面 6.OpenSSL Download页面命令 预先准备…

Nginx 在 MacOS 编译构建部署启动测试

  • 引用
  • 命令
      • 预先准备
      • 执行
  • 中级测试

引用

中级测试部分
1.nginx通过自定义header属性来转发不同的服务
构建部分
2.Nginx官网
3.Nignx构建官方文档
4.PCRE Download页面
5.Zlib官网 & Download页面
6.OpenSSL Download页面

命令

预先准备

  • nginx-1.20.1.tar.gz
  • pcre-8.45.tar.bz2
  • zlib-1.2.11.tar.gz
  • openssl-openssl-3.0.0.tar.gz

系统版本: macOS 11.4 (20F71)
内核版本: Darwin 20.5.0

执行

// 1.解压 Nginx && 依赖 【懒得写移动文件了自己随便拖进来】
$ mkdir nginx && cd nginx
$ tar xvf nginx-1.20.1.tar.gz

$ mkdir pcre && cd pcre
$ tar xvf pcre-8.45.tar.bz2

$ mkdir zlib && cd zlib
$ tar xvf zlib-1.2.11.tar.gz

$ mkdir openssl && cd openssl
$ tar xvf openssl-openssl-3.0.0.tar.gz

// 2.预配置
$ sudo mkdir /usr/local/nginx/nginx
$ cd nginx/nginx-1.20.1
$ sudo ./configure \
    --sbin-path=/usr/local/nginx/nginx \
    --conf-path=/usr/local/nginx/nginx.conf \
    --pid-path=/usr/local/nginx/nginx.pid \
    --with-http_ssl_module \
    --with-pcre=/Users/inbreeze/Downloads/pcre/pcre-8.45 \
    --with-zlib=/Users/inbreeze/Downloads/zlib/zlib-1.2.11 \
    --with-openssl=/Users/inbreeze/Downloads/openssl/openssl-openssl-3.0.0

>>  ...
    Configuration summary
      + using PCRE library: /Users/inbreeze/Downloads/pcre/pcre-8.45
      + using OpenSSL library: /Users/inbreeze/Downloads/openssl/openssl-openssl-3.0.0/
      + using zlib library: /Users/inbreeze/Downloads/zlib/zlib-1.2.11

      nginx path prefix: "/usr/local/nginx"
      nginx binary file: "/usr/local/nginx/nginx"
      nginx modules path: "/usr/local/nginx/modules"
      nginx configuration prefix: "/usr/local/nginx"
      nginx configuration file: "/usr/local/nginx/nginx.conf"
      nginx pid file: "/usr/local/nginx/nginx.pid"
      nginx error log file: "/usr/local/nginx/logs/error.log"
      nginx http access log file: "/usr/local/nginx/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"


// 3.执行编译
$ sudo make install

>>  ...
    sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
        -e "s|%%PID_PATH%%|/usr/local/nginx/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/usr/local/nginx/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
    test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
    test -d '/usr/local/nginx' \
            || mkdir -p '/usr/local/nginx'
    test ! -f '/usr/local/nginx/nginx' \
            || mv '/usr/local/nginx/nginx' \
                '/usr/local/nginx/nginx.old'
    cp objs/nginx '/usr/local/nginx/nginx'
    test -d '/usr/local/nginx' \
            || mkdir -p '/usr/local/nginx'
    cp conf/koi-win '/usr/local/nginx'
    cp conf/koi-utf '/usr/local/nginx'
    cp conf/win-utf '/usr/local/nginx'
    test -f '/usr/local/nginx/mime.types' \
            || cp conf/mime.types '/usr/local/nginx'
    cp conf/mime.types '/usr/local/nginx/mime.types.default'
    test -f '/usr/local/nginx/fastcgi_params' \
            || cp conf/fastcgi_params '/usr/local/nginx'
    cp conf/fastcgi_params \
            '/usr/local/nginx/fastcgi_params.default'
    test -f '/usr/local/nginx/fastcgi.conf' \
            || cp conf/fastcgi.conf '/usr/local/nginx'
    cp conf/fastcgi.conf '/usr/local/nginx/fastcgi.conf.default'
    test -f '/usr/local/nginx/uwsgi_params' \
            || cp conf/uwsgi_params '/usr/local/nginx'
    cp conf/uwsgi_params \
            '/usr/local/nginx/uwsgi_params.default'
    test -f '/usr/local/nginx/scgi_params' \
            || cp conf/scgi_params '/usr/local/nginx'
    cp conf/scgi_params \
            '/usr/local/nginx/scgi_params.default'
    test -f '/usr/local/nginx/nginx.conf' \
            || cp conf/nginx.conf '/usr/local/nginx/nginx.conf'
    cp conf/nginx.conf '/usr/local/nginx/nginx.conf.default'
    test -d '/usr/local/nginx' \
            || mkdir -p '/usr/local/nginx'
    test -d '/usr/local/nginx/logs' \
            || mkdir -p '/usr/local/nginx/logs'
    test -d '/usr/local/nginx/html' \
            || cp -R html '/usr/local/nginx'
    test -d '/usr/local/nginx/logs' \
            || mkdir -p '/usr/local/nginx/logs'

// 4.测试启动 [注意: /usr/local/nginx/nginx/ 为二进制目录 预配置时会提示, 建议目录名改为 sbin or bin 更符合惯例]
$ sudo /usr/local/nginx/nginx/nginx
$ curl localhost
>>  <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>

    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>

    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>

中级测试

sudo mkdir /etc/nginx
sudo vim nginx.conf
>>>
...
http {
    ...
    include /etc/nginx/*.conf;
    ...
}
...
<<<

sudo vim /etc/nginx/wx_test.conf
>>>
upstream wx {
    server 127.0.0.1:8080;
}

server {
    listen 8008;
    server_name localhost;

    root html;
    index index.html;

    charset utf-8;
    underscores_in_headers on;
    location / {
        #测试 header 转发
        if ($http_is_user = "true") {
            proxy_pass http://wx;
        }
    }
}
<<<

sudo vim /etc/nginx/wx_home.conf
>>>
server {
    listen 8080;
    server_name localhost;

    root /var/www/html;
    index wx.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
<<<

sudo mkdir -p /var/www/html
sudo vim /var/www/html/wx.html
>>>
<h1>这里是由用户触发跳转的wx页面</h1>
<<<

sudo nginx/nginx -s reload

curl --location --request GET 'localhost:8008' \
--header 'is_user: true'
<h1>这里是由用户触发跳转的wx页面~</h1>
随时随地学软件编程-关注百度小程序和微信小程序
关于找一找教程网

本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。
本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。
[【Nginx 1.20.1 基础】Nginx 在 MacOS 编译构建部署启动测试 2021_9_14]http://www.zyiz.net/tech/detail-228410.html

上一篇:linux企业运维LAMP架构----3.nginx配置管理(并发优化 负载均衡+反向代理 平滑升级 算法扩展 限流 配置管理 重定向 防盗链)

下一篇:Nginx 挂了怎么办?怎么实现高可用?

赞(0)
关注微信小程序
程序员编程王-随时随地学编程

扫描二维码或查找【程序员编程王】

可以随时随地学编程啦!

技术文章导航 更多>
扫一扫关注最新编程教程