1. Removal of LIGHTTPD
When installing LIGHTTPD on Mac OS X, I used launchctl to automate the lighttpd startup. Now, you just need to unload.
Launchctl Unload ~/library/launchagents/homebrew.mxcl.lighttpd.plist
This will immediately stop the 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 Environment2.1 Compiling and installing
Openresty compilation and installation process, on the official website is very clear, I do not repeat.
Here I assume that Openresty has been installed to the default path/usr/local/openresty.
Modify the/usr/local/openresty/nginx/conf/nginx.conf to change listen 80 under the server segment to listen 8080.
This is because port 80 can only be started by the root user. In this article we are using the current user to start Nginx.
If the 8080 port is also occupied, replace it with an available port.
2.2 Creating a Plist file
Launchctl relies on a plist configuration file to work. We need to create this file manually.
Plist is a standard XML format, which is detailed in this format, which can be seen here: Cocos2d-x in plist file format.
Launchctl has some specific requirements for the format of this configuration file and can view launchd.plist.
We created the ~/library/launchagents/org.openresty.plist file with the following content:
<?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& Gt </dict> <key>SoftResourceLimits</key> <dict> <key>NumberOfFiles</key> <inte Ger>512</integer> </dict></dict></plist>
Note that the three keys of Label, program, and programarguments must be present.
KeepAlive This value is recommended to be set to false unless daemon off is set in nginx.conf. Wayne explains in the Launchctl Note:
After setting Nginx login, it is found that the default is to generate the child process stepfather process immediately exit, resulting in launchctl in the role of keepalive configuration repeatedly start nginx, resulting in a lot of error messages, so in the setting up the daemon should pay attention to avoid such problems, Nginx can be resolved by setting daemon off, or by removing the keepalive settings.
2.3 onboarding Tasks
Launchctl Load ~/library/launchagents/org.openresty.plist
This command will start openresty directly and will start automatically the next time the system restarts.
2.4 Using 80 ports
Since it is for your own use, then using 8080 is always very annoying. To use port 80, it's also simple.
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 administrators to perform tasks as root before the user logs on.
Why not copy it into the/library/launchagent? Because Wayne mentions in the Launchctl note:
The plist under Launchagents will load in as the current logged-in user ...
Then, remove the current listener:
Launchctl Unload ~/LIBRARY/LAUNCHAGENTS/ORG.OPENRESTY.PLISTRM ~/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 is responsible for the normal HTTP service, and one is responsible for testing the Openresty function.
I wrote a script openresty for quick operation of the nginx process.
#!/bin/bashsign=${1:-reload}prefix=${2:-1}if ["$prefix" = 1]; Then prefix= '/usr/local/etc/openresty ' else prefix= "$hhl/server" Fiecho "nginx-s $sign-P $prefix" Nginx-s "$ Sign "-P" $prefix "
In actual use, I just need to call this:
#!/bin/bash openresty Reload 1openresty reopen 2
Using Openresty in OS X