OS X replaces LIGHTTPD Records with Openresty

Source: Internet
Author: User

1. Remove lighttpd

When installing LIGHTTPD on Mac OS X, I use LAUNCHCTL to automate lighttpd startup. Now, you just need to unload.

Launchctl unload ~/library/launchagents/homebrew.mxcl.lighttpd.plist

This will immediately stop LIGHTTPD from running. Next, remove the homebrew.mxcl.lighttpd.plist from the ~/library/lanuchagents directory. Otherwise, the next time you start the system, LIGHTTPD will start again.

2. Configuring the Openresty Environment

2.1 Compiling and installing

Openresty Compilation and installation process, made clear on the official website, I will not repeat.

Here I assume that Openresty has been installed to the default path/usr/local/openresty.

modifies the/usr/local/openresty/nginx/conf/nginx.conf by changing listen 80 under the server section to listen 8080.

This is because 80 ports can only be started by the root user. And in this article we are using the current user to start the nginx.

If the 8080 port is also occupied, replace it with the available port.

2.2 Creates a plist file

Launchctl relies on a plist configuration file to work. We need to create this file manually. The

Plist is a standard XML format, detailed in this format, which can be seen here: An explanation of the plist file format in Cocos2d-x. The

Launchctl Some specific requirements for the format of this profile, and you can view the launchd.plist.

The ~/library/launchagents/org.openresty.plist file we created, which reads as follows:

<?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>org.openresty</string>   <key>ProgramArguments</key>   <array>     <string>/usr/local/openresty/nginx/sbin/nginx</ String>     <string>-p</string>     <string>/usr/
Local/openresty/nginx</string>   </array>   <key>RunAtLoad</key>   <true/>   <key>KeepAlive</key>   <false/>    <key>HardResourceLimits</key>   <dict>     <key> Numberoffiles</key>     <integer>512</integer>   </dict>   <key>SoftResourceLimits</key>   <dict >     <key>NumberOfFiles</key>     <integer>512< /integer>   </dict> </dict> </plist>


Note that the three keys of Label, program, and programarguments must exist.

KeepAlive This value is recommended to false unless daemon off is set in nginx.conf. Wayne explains it in the Launchctl notes:

Set Nginx login Since the start of the discovery, because the default is to build subprocess Hofu Process exit immediately, leading to Launchctl in the keepalive configuration of the role of repeatedly start Nginx, generated a lot of error messages, so in the setting daemon should pay attention to avoid such problems, Nginx can be fixed by setting daemon off, or by removing keepalive settings.

2.3 Load Tasks

Launchctl Load ~/library/launchagents/org.openresty.plist

This command will start the openresty directly, and it will start automatically the next time the system reboots.
2.4 Use 80 port

Since it is for your own use, then using 8080 is always very unpleasant. It is also simple to use port 80.

First, copy the ~/library/launchagents/org.openresty.plist to/library/launchdaemons/org.openresty.plist:

CP ~/library/launchagents/org.openresty.plist/library/launchdaemons/org.openresty.plist

/library/launchdaemons is used by the administrator to perform tasks as root before the user logs on.

Why not copy it into the/library/launchagent? Because Wayne mentions in the Launchctl notes:

Launchagents under the plist will be the current logged-in user's identity load come in ...

Then, remove the current listener:

Launchctl Unload ~/library/launchagents/org.openresty.plist
RM ~/library/launchagents/org.openresty.plist

Finally, call Launchctl with sudo:

sudo launchctl load/library/launchdaemons/org.openresty.plist

Of course, remember to change the listening port in the Nginx configuration file to 80.

3. Shortcuts

During the development process, it is often necessary to restart the Nginx process. On my computer, there are two nginx processes, one for normal HTTP services, and one for testing openresty functions.

I wrote a script openresty used to quickly manipulate nginx processes.

#!/bin/bash
Sign=${1:-reload}
PREFIX=${2:-1}

If ["$prefix" = 1]; Then
prefix= '/usr/local/etc/openresty '
Else
prefix= "$hhl/server"
Fi

echo "Nginx-s $sign-P $prefix"
Nginx-s "$sign"-P "$prefix"

In actual use, I just need to call this on the line:

#!/bin/bash
Openresty Reload 1
Openresty Reopen 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.