hellvulture 2018-05-22
cd ~/Downloads tar xvzf pcre-8.42 cd pcre-8.42 sudo ./configure --prefix=/usr/local sudo make sudo make install
$ cd ~/Downloads tar xvzf nginx-1.14.0.tar.gz cd nginx-1.14.0 sudo ./configure --prefix=/usr/local/nginx --with-cc-opt="-Wno-deprecated-declarations" sudo make sudo make install
sudo nginx -s stop
server { listen 80; server_name sample.so; add_header Cache-Control private; charset utf-8; fastcgi_intercept_errors on; location / { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_intercept_errors on; } }
1、新建文件
sudo vim /Library/LaunchDaemons/com.nginx.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.nginx.plist</string> <key>ProgramArguments</key> <array> <string>/usr/local/nginx/sbin/nginx</string> </array> <key>KeepAlive</key> <false/> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/usr/local/nginx/logs/error.log</string> <key>StandardOutPath</key> <string>/usr/local/nginx/logs/access.log</string> </dict> </plist>
sudo chmod 644 /Library/LaunchDaemons/com.nginx.plist
3、注册为系统服务
sudo launchctl load -w /Library/LaunchDaemons/com.nginx.plist # 以下为卸载 sudo launchctl unload -w /Library/LaunchDaemons/com.nginx.plist
4、重启后查看nginx是否启动
ps -ef | grep nginx
0 169 1 0 3:07下午 ?? 0:00.00 nginx: master process /usr/local/nginx/sbin/nginx 0 170 169 0 3:07下午 ?? 0:00.00 nginx: worker process 501 928 399 0 3:43下午 ttys000 0:00.00 grep nginx