• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Kevin Cheng's Yard
电脑是我的老婆,编程是我的灵魂,代码是我的语言,按键是我在歌唱。
https://github.com/surfsky/
博客园    首页    新随笔    联系   管理    订阅  订阅

在 MAC 下配置 Nginx

nginx

1. 更新Homebrew

 

# mac使用brew update无反应,更新慢解决办法
# 替换brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

# 替换homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

# update
brew update

 

2. 安装 nginx

 

$ brew install nginx

==> Installing dependencies for nginx: openssl@1.1 and pcre

==> Installing nginx dependency: openssl@1.1

==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl@1.1

blablablabla....

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that

nginx can run without sudo. 

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:

  brew services start nginx

Or, if you don't want/need a background service you can just run:

  nginx

 

3. 启动Nginx

登录时作为服务启动: brew services start nginx
直接启动: nginx
默认地址:http://localhost:8080

 

4. 部署新网站

修改文件 /usr/local/etc/nginx/nginx.conf,可用 sudo pico /usr/local/etc/nginx/nginx.conf,或者直接用记事本编辑。

    # 配置网站
    server {
        listen 8081;
        server_name   localhost;
        location / {
            root     /XXX/DemoSite;
            index    index.html;
        }
    }

重新启动nginx

sudo nginx -s reload

 打开浏览器查看:

http://localhost:8081/

 

转载请注明出处:http://surfsky.cnblogs.com 

posted @ 2020-04-15 15:02  surfsky  阅读(364)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3