栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

手把手教你Mac M1简单快速配置Nginx

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

手把手教你Mac M1简单快速配置Nginx

教你Mac M1简单快速配置Nginx

相信很多入手Mac产品的小伙伴们都有一个头疼的问题!如何配置/安装程序员日常使用的软件/插件呢?今天小编就带大家了解如何快速安装配置好Nginx。

1、了解Nginx
  1. 是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。

  2. 常用于做请求转发、负载均衡、动静分离的一款反向代理服务器。

  3. Nginx以事件驱动的方式编写,所以有非常好的性能,同时也是一个非常高效的反向代理、负载平衡服务器。在性能上,Nginx占用很少的系统资源,能支持更多的并发连接,达到更高的访问效率;在功能上,Nginx是优秀的代理服务器和负载均衡服务器;在安装配置上,Nginx安装简单、配置灵活。

  4. Nginx支持热部署,启动速度特别快,还可以在不间断服务的情况下对软件版本或配置进行升级,即使运行数月也无需重新启动。

  5. 在微服务的体系之下,Nginx正在被越来越多的项目采用作为网关来使用,配合Lua做限流、熔断等控制。

  6. 对于Nginx的初学者可能不太容易理解web服务器究竟能做什么,特别是之前用过Apache服务器的,以为Nginx可以直接处理php、java,实际上并不能。对于大多数使用者来说,Nginx只是一个静态文件服务器或者http请求转发器,它可以把静态文件的请求直接返回静态文件资源,把动态文件的请求转发给后台的处理程序,例如php-fpm、apache、tomcat、jetty等,这些后台服务,即使没有nginx的情况下也是可以直接访问的。

2、安装 Homebrew
  1. 首先 homebrew是什么?它是Mac中的一款软件包管理工具,通过homebrew可以很方便的在Mac中安装软件或者是卸载软件。不了解的同学看以看官网[https://brew.idayer.com/guide/start/],然后在我们命令行中复制如下命令:
		/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
  1. 如果最后安装完成后出现==> Installation successful! 就说明安装成功了。

  2. 通过 brew update 命令进行homebrew更新。

  3. 配置环境变量操作如下
    从macOS Catalina(10.15.x) 版开始,Mac 使用 zsh 作为默认 Shell ,使用 .zprofile。M1 款的 MacBook 肯定是比这个版本高的, 所以对应命令:

    	echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
    	eval "$(/opt/homebrew/bin/brew shellenv)" 
    
  4. 设置镜像「本文设置为中科大镜像」

		git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
3、安装 Nginx
  1. 我们使用homebrew进行Nginx安装操作,Nginx安装命令如下:
	brew install nginx
  1. 查看Nginx配置信息:
	brew info nginx

  1. 启动/重启Nginx命令:
    启动Nginx命令:brew services start nginx
    重启Nginx命令: brew services restart nginx

  2. 启动完Nginx后,通过在网页输入 http://localhost:8080/ 「Nginx默认端口号8080」

  3. 如果小伙伴需要通过Nginx来配置请求转发则需要修改配置文件nginx.conf
    通过终端命令进入到nginx.conf文件所在地:

		open /opt/homebrew/etc/nginx

  1. 修改配置文件
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  script_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
     	server {
             listen       9001;
             server_name  localhost;

     		location ~ /eduservice/ {
     			proxy_pass http://localhost:8001;
            }
                 location ~ /eduoss/ {
     			proxy_pass http://localhost:8002;
         }
     }
    include servers/*;
}
  1. 修改操作图「修改完后记得重启Nginx」:
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/695544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号