Installation and deployment of OpenResty under Windows 10, and support running PHP and Lua at the same time
1. URL: http://openresty.org/cn/download.html , download and install: 64-bit Windows: openresty-1.19.9.1-win64.zip.
2. Unzip to the directory: C:\OpenResty-1.19.9.1-Win64. as shown in Figure 1
3. Usage documentation for Windows version of OpenResty: https://github.com/openresty/openresty/blob/master/doc/readme-windows.md . Start the Nginx server of the Win64 binary distribution of Openresty.
PS C:\openresty-1.19.9.1-win64> start nginx PS C:\OpenResty-1.19.9.1-Win64>
4. Check the task manager, in addition to the native Nginx software, it has also added: nginx.exe. as shown in Figure 2
5. Then you can use the tasklist command to view the nginx process running in the background. 2 of them are native Nginx software. as shown in Figure 3
PS C:\openresty-1.19.9.1-win64> tasklist /fi "imagename eq nginx.exe" Image Name PID Session Name Session# Memory Use ====================================================== =========== Nginx.exe 15816 console 1 7,400 K Nginx.exe 93052 console 1 11,380 K Nginx.exe 97096 console 1 8,848 K Nginx.exe 117120 console 1 9,364 K PS C:\openresty-1.19.9.1-win64> ./nginx -s stop PS C:\openresty-1.19.9.1-win64> tasklist /fi "imagename eq nginx.exe" Image Name PID Session Name Session# Memory Use ====================================================== =========== Nginx.exe 15816 console 1 11,652 K nginx.exe 114616 console 1 15,888 K PS C:\OpenResty-1.19.9.1-Win64>
6. The Resty command line utility requires the Perl interpreter to be installed on your system and visible to your PATH environment. Any Perl distribution should work, including StrawberryPerl, ActivePerl, and MSYS2 Perl. URL: https://strawberryperl.com/ . Perl for MS Windows, free! Download and install Strawberry-Perl-5.32.1.1-64bit.msi.
7. Edit the PATH environment variable, create a new: C:\OpenResty-1.19.9.1-Win64 . as shown in Figure 4
8. Restart the computer. Run the Resty script. It is planned to uninstall the native Nginx software in the future. Because the functions of the two overlap a lot. as shown in Figure 5
PS C:\Windows\System32> tasklist /fi "imagename eq nginx.exe" Info: No running task matches the specified criteria. PS C:\Windows\System32> cd .. PS C:\Windows> cd .. PS C:\> cd .\openresty-1.19.9.1-win64\ PS C:\openresty-1.19.9.1-win64> tasklist /fi "imagename eq nginx.exe" Info: No running task matches the specified criteria. PS C:\openresty-1.19.9.1-win64> start nginx PS C:\openresty-1.19.9.1-win64> tasklist /fi "imagename eq nginx.exe" Image Name PID Session Name Session# Memory Use ====================================================== =========== Nginx.exe 12652 console 1 8,972 K Nginx.exe 17092 console 1 9,512 K PS C:\openresty-1.19.9.1-win64> resty-e "ngx.say(Hello, openresty!)" Hello, openresty! PS C:\OpenResty-1.19.9.1-Win64> cd .. ps c:\> resty -e "ngx.say(Hello, openresty!)" Hello, openresty! PS C:\>
9. Migrate the configuration item of the native nginx software nginx.conf to the nginx.conf of openresty. Reload, report an error. as shown in Figure 6
PS C:\openresty-1.19.9.1-win64> nginx -s reload nginx:[warn]The "SSL" directive is deprecated, use the "listen ... nginx:[warn]The "SSL" directive is deprecated, use the "listen ... SSL" directive instead c:/openresty-1.19.9.1-win64/conf/vhosts/mssi-main.conf:14 nginx:[emerg]Could not build server_names_hash, you should increase server_names_hash_bucket_size: 64 PS C:\OpenResty-1.19.9.1-Win64>
10. After editing nginx.conf, reload, no more errors. as shown in Figure 7
Before adjustment:
http {
include mime.types;
default_type application/octet-stream;
#log_format main$remote_addr - $remote_user[$time_local]"$request"
#$STATUS $BODY_BYTES_SENT "$HTTP_REFERER"
#"$http_user_agent" "$http_x_forwarded_for";
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 443;
server_name localhost;
client_max_body_size 200M;
client_body_buffer_size 1024K;
fastcgi_read_timeout 180s;
#charset koi8-r;
#access_log logs/host.access.log main;
ssl on;
ssl_certificate localhost.pem;
ssl_certificate_key localhost-key.pem;
After adjustment:
http {
include mime.types;
default_type application/octet-stream;
#log_format main$remote_addr - $remote_user[$time_local]"$request"
#$STATUS $BODY_BYTES_SENT "$HTTP_REFERER"
#"$http_user_agent" "$http_x_forwarded_for";
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server_names_hash_max_size 1024;
server_names_hash_bucket_size 128;
server {
listen 443 SSL;
server_name localhost;
client_max_body_size 200M;
client_body_buffer_size 1024K;
fastcgi_read_timeout 180s;
#charset koi8-r;
#access_log logs/host.access.log main;
ssl_certificate localhost.pem;
ssl_certificate_key localhost-key.pem;
location / {
root e:/wwwroot;
index index.html index.htm index.php;
}
#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;
}
# proxy the php scripts to apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the php scripts to fastcgi server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
root e:/wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_filename $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if apaches document root
# concurs with nginxs one
#
#location ~ /\.ht {
# deny all;
#}
}
# https server
#
#server {
# listen 443 SSL;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:ssl:1m;
# ssl_session_timeout 5M;
# ssl_ciphers high:!anull:!md5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include c:/openresty-1.19.9.1-win64/conf/vhosts/*.conf;
## php-fpm servers ##
upstream php-fpm {
Server 127.0.0.1:9000;
}
}
PS C:\openresty-1.19.9.1-win64> nginx -s reload PS C:\openresty-1.19.9.1-win64> resty-e "ngx.say(Hello, openresty!)" Hello, openresty! PS C:\OpenResty-1.19.9.1-Win64>
11. Note, all commands must go to the directory: C:\OpenResty-1.19.9.1-Win64 and execute. Otherwise, there will be some unexpected errors.
PS C:\Windows\System32> cd .. PS C:\Windows> cd .. PS C:\> Start Nginx ps c:\> php-cgi.exe -b 127.0.0.1:9000-c c:/php-7.4.6/php.ini PS C:\> nginx -s reload nginx:[alert]could not open error log file: createFile() "./logs/error.log" failed (3: the system cannot find the path specified) 2021/09/17 19:04:54[emerg]3708#3712: createFile() "./conf/nginx.conf" failed (3: the system cannot find the path specified) PS C:\> cd .\openresty-1.19.9.1-win64\ PS C:\openresty-1.19.9.1-win64> nginx -s reload nginx:[error]createFile() "./logs/nginx.pid" failed (2: the system cannot find the file specified) PS C:\openresty-1.19.9.1-win64> tasklist /fi "imagename eq nginx.exe" Info: No running task matches the specified criteria. PS C:\openresty-1.19.9.1-win64> start nginx PS C:\openresty-1.19.9.1-win64> tasklist /fi "imagename eq nginx.exe" Image Name PID Session Name Session# Memory Use ====================================================== =========== Nginx.exe 3712 console 1 18,068 K Nginx.exe 13172 console 1 18,560 K PS C:\openresty-1.19.9.1-win64> nginx -s reload PS C:\OpenResty-1.19.9.1-Win64>
12. Run the php program and run normally. as shown in Figure 8
13. Add Lua’s server
server {
listen 443 SSL;
server_name morefunresty.dev.chinamcloud.cn;
Charset UTF-8;
lua_need_request_body on;
access_log logs/morefunresty.dev.chinamcloud.cn.access.log;
error_log logs/morefunresty.dev.chinamcloud.cn.error.log;
ssl_certificate vhosts/morefunresty.dev.chinamcloud.cn.pem;
ssl_certificate_key vhosts/morefunresty.dev.chinamcloud.cn-key.pem;
location / {
if ($request_method = options ) {
add_header content-length 0;
add_header content-type text/plain;
return 200;
}
}
location ~ ^/lua/api/vote/([-_a-zA-Z0-9/]+) {
default_type application/json;
access_by_lua_file e:/wwwroot/msi_main/resty/app/common/boot/bootstrap.lua;
content_by_lua_file e:/wwwroot/msi_main/resty/app/mods/vote/$1.lua;
}
location ~ ^/lua/api/poll/([-_a-zA-Z0-9/]+) {
default_type application/json;
access_by_lua_file e:/wwwroot/msi_main/resty/app/common/boot/bootstrap.lua;
content_by_lua_file e:/wwwroot/msi_main/resty/app/mods/poll/$1.lua;
}
location ~ ^/lua/api/draw/([-_a-zA-Z0-9]+) {
default_type application/json;
access_by_lua_file e:/wwwroot/msi_main/resty/app/common/boot/bootstrap.lua;
content_by_lua_file e:/wwwroot/msi_main/resty/app/mods/draw/$1.lua;
}
location /draw/times {
internal;
content_by_lua_file e:/wwwroot/msi_main/resty/app/mods/draw/times_check.lua;
}
}
14. Refer to the entry document: https://openresty.org/cn/getting-started.html . Run the Lua program and respond normally. in line with expectations. as shown in Figure 9








