在MacOSX10.9上编译安装nginx

1、先要确定是否安装了PCRE库

可以在这里下载最新版本的pcre源码。
博主下载的是pcre-8.37版本,接下来进行安装:

1
2
3
4
$cd ~/Desktop/
$tar xzf pcre-8.37.tar.gz && cd pcre-8.37
$sudo ./configure --prefix=/usr/local
$sudo make && sudo make install

2、安装Nginx

先上Nginx的官网下载最新的稳定版本,博主使用1.10.1版本。

1
2
3
4
5
6
7
8
9
10
$cd ~/Desktop/
$tar xzf nginx-1.10.1.tar.gz && cd nginx-1.10.1
$mkdir /usr/local/nginx
$sudo chown 777 /usr/local/nginx/logs/*.log
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--with-http_ssl_module \
--with-http_stub_status_module
$sudo make install

添加软连接

1
$ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

3、nginx的基本操作

================

启动nginx

1
$sudo nginx

停止nginx

1
$sudo nginnginx -s stop

重启nginx

1
$sudo nginx -s reload

4、nginx的配置

=============

修改nginx配置文件

1
$sudo vi /usr/local/nginx/nginx.conf

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#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 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /Users/Wenhao.Wu/WebSites;
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;
}
}
}

轻狂书生 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!