Giter Site home page Giter Site logo

openresty-tutorial's Introduction

Openresty Tutorial

Some quick primers about Openresty and experimenting with Lua inside the Nginx.

Different lessons are available in branches. Some branches only have an *-init branch. These are branches to demonstrate certain aspects of Openresty. Other branches have both an *-init as well as a *-solution branch. Where the init branch can be used as the start of an excersise and the solution branch contains the solution.

Note, some init branches when run result in errors, this is delibirate to demonstrate certain pitfalls in Openresty.

Lesson 1

the start is to simply observer the different Nginx phases. Checkout the branch lesson-1-init start the nginx server by executing:

nginx -p `pwd`/ -c conf/nginx.conf

Nginx is started as a foreground process with stdout as log. This makes it easier to restart and observe the logging. When Nginx is started observe the logging, it should among other things contai:

...
nginx: [warn] [lua] init-phase.lua:1: hello from the init phase
...
2023/08/04 10:55:53 [notice] 3634383#3634383: *1 [lua] init-worker-phase.lua:1: hello from the init worker phase, context: init_worker_by_lua*

Now make a request to the endpoint and observe the logging again:

2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] set-phase.lua:1: hello from the set phase, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] rewrite-phase.lua:1: hello from the rewrite phase, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] access-phase.lua:1: hello from the access phase, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] content-phase.lua:1: hello from the content phase, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] header-filter-phase.lua:1: hello from the header-filter phase, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] body-filter-phase.lua:1: hello from the body-filter phase, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [error] 3634383#3634383: *2 attempt to set ngx.header.HEADER after sending out response headers, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] body-filter-phase.lua:1: hello from the body-filter phase, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [error] 3634383#3634383: *2 attempt to set ngx.header.HEADER after sending out response headers, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2023/08/04 10:57:28 [notice] 3634383#3634383: *2 [lua] log-phase.lua:1: hello from the log phase while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"

openresty-tutorial's People

Watchers

Pim Gaemers avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.