2014-04-18 22:57:01
来 源
itjs.cn
Nginx
本文介绍mac系统上安装配置Nginx和PHP环境,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。
安装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

<?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">z

<dict>

<key>KeepAlive</key>

<true/>

<key>Label</key>

<string>org.nginx.nginx</string>

<key>LaunchOnlyOnce</key>

<true/>

<key>NetworkState</key>

<true/>

<key>ProgramArguments</key>

<array>

<string>/usr/local/nginx/sbin/nginx</string>

</array>

<key>RunAtLoad</key>

<true/>

<key>ServiceDescription</key>

<string>Nginx web server</string>

<key>StandardErrorPath</key>

<string>/var/log/system.log</string>

</dict>

</plist>

配置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;

}

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。