当前位置:   article > 正文

MAC 安装nginx_mac安装nginx

mac安装nginx

使用Homebrew方式进行安装

步骤:

1、更新 Homebrew

brew update

2、下载并安装 Nginx

brew install nginx

3、查看 nginx 配置信息

brew info nginx
  1. zhanghua@Breeze ~ % brew info nginx
  2. // 版本信息
  3. ==> nginx: stable 1.25.1 (bottled), HEAD
  4. HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
  5. // Nginx安装目录
  6. https://nginx.org/
  7. /usr/local/Cellar/nginx/1.25.1_1 (26 files, 2.4MB) *
  8. Poured from bottle using the formulae.brew.sh API on 2023-08-10 at 10:48:47
  9. // 安装来源
  10. From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
  11. License: BSD-2-Clause
  12. ==> Dependencies
  13. Required: openssl@3 ✔, pcre2
  14. ==> Options
  15. --HEAD
  16. Install HEAD version
  17. // 根目录
  18. ==> Caveats
  19. Docroot is: /usr/local/var/www
  20. // 重点!!!nginx 的配置文件及默认启动端口 8080
  21. The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
  22. nginx can run without sudo.
  23. // Nginx将在 Server 目录下加载所有文件,在这个
  24. nginx will load all files in /usr/local/etc/nginx/servers/.
  25. To start nginx now and restart at login:
  26. brew services start nginx
  27. Or, if you don’t want/need a background service you can just run:
  28. /usr/local/opt/nginx/bin/nginx -g daemon off;
  29. ==> Analytics
  30. install: 11,885 (30 days), 57,023 (90 days), 84,746 (365 days)
  31. install-on-request: 11,855 (30 days), 56,930 (90 days), 84,620 (365 days)
  32. build-error: 3 (30 days)

4、nginx常用命令

  1. 启动
  2. brew services start nginx
  3. 停止
  4. brew services stop nginx
  5. 终端进入nginx 目录
  6. cd /opt/homebrew/etc/nginx
  7. 编辑 nginx.conf 配置文件
  8. vim nginx.conf
  9. 编辑完成后:wq保存退出
  10. 重新加载配置文件
  11. nginx -s reload

5、nginx配置文件 nginx.conf

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. #http 配置
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. sendfile on;
  19. #tcp_nopush on;
  20. #keepalive_timeout 0;
  21. keepalive_timeout 65;
  22. #gzip on;
  23. upstream xx{
  24. // 负载均衡配置
  25. server 127.0.0.1:8080 weight =1;
  26. server 127.0.0.1:8081 weight =1;
  27. }
  28. // nginx 端口 ,只要访问8080端口 就会被nginx 监听 ,如果电脑端口有冲突 可以更换端口号
  29. server {
  30. listen 8080;
  31. server_name localhost;
  32. #charset koi8-r;
  33. #access_log logs/host.access.log main;
  34. location / {
  35. root html;
  36. index index.html index.htm;
  37. // 反向代理
  38. proxy_pass http://域名
  39. }
  40. #error_page 404 /404.html;
  41. # redirect server error pages to the static page /50x.html
  42. #
  43. error_page 500 502 503 504 /50x.html;
  44. location = /50x.html {
  45. root html;
  46. }
  47. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  48. #
  49. #location ~ \.php$ {
  50. # proxy_pass http://127.0.0.1;
  51. #}
  52. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  53. #
  54. #location ~ \.php$ {
  55. # root html;
  56. # fastcgi_pass 127.0.0.1:9000;
  57. # fastcgi_index index.php;
  58. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  59. # include fastcgi_params;
  60. #}
  61. # deny access to .htaccess files, if Apache's document root
  62. # concurs with nginx's one
  63. #
  64. #location ~ /\.ht {
  65. # deny all;
  66. #}
  67. }
  68. # another virtual host using mix of IP-, name-, and port-based configuration
  69. #
  70. #server {
  71. # listen 8000;
  72. # listen somename:8080;
  73. # server_name somename alias another.alias;
  74. # location / {
  75. # root html;
  76. # index index.html index.htm;
  77. # }
  78. #}
  79. # HTTPS server
  80. #
  81. #server {
  82. # listen 443 ssl;
  83. # server_name localhost;
  84. #证书 cert.pen和 cert.key换成证书的目录
  85. # ssl_certificate cert.pem;
  86. # ssl_certificate_key cert.key;
  87. # ssl_session_cache shared:SSL:1m;
  88. # ssl_session_timeout 5m;
  89. # ssl_ciphers HIGH:!aNULL:!MD5;
  90. # ssl_prefer_server_ciphers on;
  91. # location / {
  92. # root html;
  93. # index index.html index.htm;
  94. # }
  95. #}
  96. include servers/*;
  97. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/875919
推荐阅读
相关标签
  

闽ICP备14008679号