【Nginx 1.20.1 基础】Nginx 在 MacOS 编译构建部署启动测试 2021_9_14
2021/9/15 7:08:13
本文主要是介绍【Nginx 1.20.1 基础】Nginx 在 MacOS 编译构建部署启动测试 2021_9_14,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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>
这篇关于【Nginx 1.20.1 基础】Nginx 在 MacOS 编译构建部署启动测试 2021_9_14的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-13用Nginx防范DDoS攻击的那些事儿
- 2024-12-13用Terraform在AWS上搭建简单NGINX服务器指南
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享