作者:书友51676198 | 来源:互联网 | 2014-05-28 09:40
安装Nginx方法1:使用brew.brewinstallnginx按提示操作,安装完成后nginx的配置文件在/usr/local/etc/nginx/nginx.conf。启动nginx:nginx或者sudonginx注意:若nginx的监听端口为1024以下,则需要使用sudo,否则会出现Permissiond
安装Nginx 方法1:
使用brew.
brew install
nginx
按提示操作,安装完成后nginx的配置文件在/usr/local/etc/nginx/nginx.conf。
启动nginx:
nginx 或者 sudo nginx
注意:若nginx的监听端口为1024以下,则需要使用sudo,否则会出现Permission denied.
停止 nginx (
sudo)nginx-sstop
自动启动
You can start nginx automatically on login running as your user
with:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/nginx/1.0.8/org.nginx.nginx.plist
~/Library/LaunchAgents/
launchctl load -w
~/Library/LaunchAgents/org.nginx.nginx.plist
禁止自动启动
launchctl unload -w
~/Library/LaunchAgents/org.nginx.nginx.plist
rm ~/Library/LaunchAgents/org.nginx.nginx.plist
方法2:
下载源码编译
cd ~/SourceCache
curl -O
http://nginx.org/download/nginx-1.0.4.tar.gz
tar -xzf nginx-1.0.4.tar.gz
cd nginx-1.0.4
brew install pcre
./configure --prefix=/usr/local/nginx
--pid-path=/usr/local/nginx/var/run/nginx.pid
--with-http_ssl_module
make
sudo make install
自动启动
sudo nano /Library/LaunchDaemons/org.nginx.nginx.plist
z
KeepAlive
Label
org.nginx.nginx
LaunchOnlyOnce
NetworkState
ProgramArguments
/usr/local/nginx/sbin/nginx
RunAtLoad
ServiceDescription
Nginx web server
StandardErrorPath
/var/log/system.log
配置nginx
sudo mkdir /usr/local/etc/nginx/sites-available
sudo mkdir /usr/local/etc/nginx/sites-enable
sudo nano /usr/local/etc/nginx/nginx.conf
在
http{
…
server{
...
}
include sites-enabled/*.conf;
}