Alternative to nginx openresty installation notes

Time:2021-7-31

Nginx is a well-known HTTP server, which is widely used in HTTP services, reverse proxy, load balancing and other scenarios.

But sometimes we need to complete some more complex forwarding functions. At this time, we need to add some modules to nginx. Because most of these modules are not provided by nginx by default, it is not easy to install.

Openresty encapsulates nginx and turns nginx into a more powerful and universal web application platform by bringing together various well-designed nginx modules (mainly independently developed by openresty team).

install

Take MacOS as an example. For other systems, please refer toOfficial documentation installation tutorial
If our computers were previously usedwrongIf nginx is installed in brew mode, it needs to be deleted:

# which nginx 
/usr/local/bin/nginx
# rm -rf /usr/local/bin/nginx

If you care about the space occupied by nginx installation files, you need to delete them/usr/local/etc/nginxas well as/Usr / local / cell / nginx / < corresponding version number >folder.

Then install openresty using the following command:

brew install openresty/brew/openresty

If you have previously used brew to install nginx, you also need to execute the following commands:

brew untap homebrew/nginx

At this point, we will/usr/local/optNew found in folderopenrestyfolder.

environment variable

openrestyFolder containsnginxFolder. If nginx command is used in the global shell, you also need tonginxIn foldersbinAdd folder to environment variable:

# export PATH=/usr/local/opt/openresty/nginx/sbin:$PATH
# echo $PATH

To take effect automatically the next time you start the shell, you also need to execute the following command:

# echo "export PATH=/usr/local/opt/openresty/nginx/sbin:$PATH" >> ~/.bash_profile

use

At this point, we can use nginx function as usual.

# nginx -T
# nginx

Example

When configuring nginx, you can useechoTo output the value of the variable, which is very important for debugging the configuration file of nginx:

server {
        listen       6006;
        server_name  localhost;
        location / {
            #Custom content type
            default_type text/html;
            
            #Output current time
            echo $date_local;
        }
    }

Then access at this timehttp://localhost: 6006, the variable $date will be obtained_ Value of local:
Alternative to nginx openresty installation notes

other

Openresty encapsulatesA large number of componentsAt the same time, a model namedOPMComponent manager for. I hope I can use them one day.

summary

Openresty will be more powerful armed with nginx. When nginx can’t meet our new needs well, don’t be afraid to come to openresty.

Postscript: FreeBSD’s ports provides nginx with the option to install third-party plug-ins such as echo.

Recommended Today

002.00 picture processing pil.image

002.00 image processing Filing date: August 10, 2019Updated on: 2021 / 03 / 05 add im. N_ frames Win 10 Python 3.7.4 PIL Pillow 6.1.0 Subject: 002.00 image processing Coordinate system The upper left corner (x, y) is (0, 0), in fact (0.5, 0.5), and the horizontal right and vertical down are positive Most references […]