我是用root用户装的

1.先安装PCRE库

可以在这里下载最新版,我这里使用的是8.33的版本然后在终端执行下面的命令。

cd ~/Download 
tar xvzf pcre-8.33.tar.gz 
cd pcre-8.12 
sudo ./configure --prefix=/usr/local 
sudo make 
sudo make install
 
或者更简单的方式:

yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

2.下载安装nginx

首先在nginx官网下载最新的源码,我这里用的是nginx-1.5.2

tar -zvxf nginx-1.5.2.tar.gz 
cd nginx-1.5.2 
./configure  --prefix=/usr/local/nginx
注: nginx默认是安装到/opt目录下,在mac系统中是没有/opt目录的,所以用--prefix指定目标目录

默认编译概要:

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library

# 默认编译参数对应的安装路径(*_temp 为目录)
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/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"

为了方便:

sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
sudo ln -s /usr/local/nginx/conf /etc/nginx
sudo ln -s /usr/local/nginx/logs/nginx.pid /var/run/nginx.pid
sudo ln -s /usr/local/nginx/logs /var/log/nginx

或者直接在编译时设定

./configure \
--prefix=/usr/local \
--sbin-path=/usr/local/sbin \
--conf-path=/etc/nginx \
--pid-path=/var/run \
--error-log-path=/var/log/nginx \
--http-log-path=/var/log/nginx

编译参数参考 Nginx InstallOption

3.启动Nginx

检查PATH环境变量

 # ~/.bash_profile export PATH=/usr/local/bin:/usr/local/sbin:$PATH

启动Nginx

 sudo nginx
查看是否启动成功 :在浏览器中输入http://localhost 回车

需要停止Nginx的时候运行

 sudo nginx -s stop

4.配置自启动

创建文件 /System/Library/LaunchDaemons/nginx.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key><string>nginx</string>
    <key>Program</key><string>/usr/local/sbin/nginx</string>
    <key>KeepAlive</key><true/>
    <key>NetworkState</key><true/>
    <key>StandardErrorPath</key><string>/var/log/system.log</string>
    <key>LaunchOnlyOnce</key><true/>
  </dict>
</plist>

载入自启动文件

 launchctl load -F /System/Library/LaunchDaemons/nginx.plist
 

mac 安装 nginx的更多相关文章

  1. mac 安装nginx

    首先准备工作,打开mac终端 1.安装brew  输入命令 curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar x ...

  2. mac 安装 nginx 环境

    1.brew search nginx 2.brew install nginx 启动nginx ,sudo nginx ;访问localhost:8080 发现已出现nginx的欢迎页面了. 备注: ...

  3. Mac安装nginx配置过程

    mac电脑系统重装了,记录一下安装nginx的过程: 1.打开终端 2.安装Command Line tools xcode-select --install 3.安装brew命令 ruby -e & ...

  4. mac 安装nginx,并配置nginx的运行环境

    1. 安装nginx // 查询有没有nginx brew search nginx //开始安装nignx brew install nginx 2. 检查nignx是否安装成功 nginx -V ...

  5. 2019.1.10 Mac安装Nginx服务器

    1.安装Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/in ...

  6. Mac 安装nginx之后重启、停止、开启等操作

    操作系统:macOs High Sierra 10.13.6 1.我用的homebrew安装的nignx1.15.9,安装完成之后会有下面的提示: 网站根目录在:/usr/local/var/www ...

  7. Mac安装Nginx、Mysql、PHP、Redis

    安装xcode命令行工具的命令 xcode-select --install   安装homebrew: ruby -e "$(curl -fsSL https://raw.githubus ...

  8. mac安装nginx

    1,http://nginx.org/en/download.html下载http://nginx.org/download/nginx-1.2.0.tar.gz 2,tar -xf nginx-1. ...

  9. 《OD大数据实战》mac下安装nginx+php

    一.mac安装nginx + php + php-fpm  或apache + php 1. Mac 下 Nginx.MySQL.PHP-FPM 的安装配置 2. Mac下安装LNMP(Nginx+P ...

随机推荐

  1. OK335xS U-boot 环境变量解析

    /************************************************************************************************** ...

  2. linux-*.filetype.bz2 unzip

    how to unzip *.bz2 file? wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 unzip ...

  3. MySQL设置默认编码

    查看默认编码:show variables like "char%" MySQL5.5以下版本: 1.打开配置文件 2.在[client]和[mysqld]字段下面均添加defau ...

  4. Tomcat问题:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined ,At least one of these environment variable is needed to run this program

    一眼就能看出来是jdk的环境有问题,但是用了这么久的jdk一直都配置的好好的,怎么一到Tomcat上就这么矫情了. 最后查解决方案,原来是我的jdk从官网直接下载的,虽然我修改了java_home,但 ...

  5. BZOJ4475: [Jsoi2015]子集选取【找规律】【数学】

    Description Input 输入包含一行两个整数N和K,1<=N,K<=10^9 Output 一行一个整数,表示不同方案数目模1,000,000,007的值. Sample In ...

  6. unknown error: call function result missing 'value'

    好好的脚本全部报错,遇到这种现在看一下自己Chrome浏览的版本号 然后去chromedriver官网上下载最新驱动文件 https://sites.google.com/a/chromium.org ...

  7. (转)typedef和define的详细区别

    来源:http://developer.51cto.com/art/201104/256060.htm typedef是一种在计算机编程语言中用来声明自定义数据类型,配合各种原有数据类型来达到简化编程 ...

  8. python open和file的区别

    opne和file都是用来对文件的操作 open:内置函数,使用方式是open('file_name', mode, buffering),返回值是一个file对象,以写模式打开文件如果不存在会被创建 ...

  9. dbt 包管理

    dbt 可以方便的支持基于git 的包管理 依赖申明 位置 dbt_project.yml 中的repositories 或者使用packages.yaml 格式 dbt_project.yml: r ...

  10. 自适应巡航控制系统——ACC

    ACC(Adaptive Cruise Control)自适应巡航控制系统(以下简称ACC)是一种基于传感器识别技术而诞生的智能巡航控制,相比只能根据驾驶者设置的速度进行恒定速度巡航的传统巡航控制系统 ...