Windows安装Nginx、OpenResty

nginx下载或OpenResty下载

我这里下载的openresty-1.19.9.1-win64.zip,解压即可

查看版本

nginx -v
nginx -V

启动

点击nginx.exe

在nginx目录打开cmd命令行,执行以下:

start nginx

在浏览器地址栏输入网址 http://localhost:80,查看是否启动成功

关闭

nginx -s stop 立即停止nginx,不保存相关信息
nginx -s quit 正常退出nginx,并保存相关信息
nginx -s reload 重启(改变配置后,需重启)
taskkill /f /t /im nginx.exe 彻底关闭

配置

Nginx的配置文件是conf目录下的nginx.conf,默认配置的nginx监听的端口为80,也可以更改为别的

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

输出hello,world

		location / {
            default_type text/html;
            content_by_lua_block {
				ngx.say("<p>hello,world<p>")
			}
        }
nginx -s reload 重启(改变配置后,需重启)

查看nginx进程

$ tasklist | findstr nginx
nginx.exe                    23360 Console                    2     11,368 K
nginx.exe                    26500 Console                    2     11,984 K

两个进程,一个为master进程,一个为worker进程

反向代理

负载均衡

动静分离

posted @ 2022-02-26 21:31  请务必优秀  阅读(443)  评论(0编辑  收藏  举报