热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Nginx服务器中配置lua+fastcgi

I’verecentlybeendoingsometestinginlua,andhavebeencomparingtheresultstotheEdgeLinkConsultingCMSthatwe’vedesignedinPHP.Sofarthissolutionisabletoservesubstantially
I’ve recently been doing some testing in lua, and have been comparing the results to the EdgeLink Consulting CMS that we’ve designed in PHP. So far this solution is able to serve substantially more requests per second than our current CMS. However, we haven’t really spent much time optimizing the CMS. The goal is to have a working copy first before any optimizations are done. We’ve also been working on some eCommerce modules for the platform.
With all that being said, I’d like to post a quick tutorial on how I got this setup. It was quite the task. Although there was a tutorial I found to do the same task, it was a little bit confusing. My tutorial will have a lot of the same steps, with some minor adjustments. This tutorial is written at an intermediate level. Some trivial steps have been omitted.

NOTE: This has been tested with Debian 5.0.4 (Stable)

Install nginx
 apt-get install nginx
We’ll have to do some modifications later on to add the FastCGI handler. For simplicity we will keep the web path to “/var/www/nginx-default” and listen on port 8081 in case you have another webserver running on port 80.

Install lua 5.1 (and WSAPI libraries)
apt-get install lua5.1 liblua5.1-wsapi-fcgi-0 liblua5.1-coxpcall0 liblua5.1-filesystem0
apt-get install liblua5.1-wsapi-doc
Can’t do much testing without this. Note: The second line is not necessary if you are running Debian testing, and get the liblua5.1-wsapi-fcgi-1instead.
EDIT: You’ll notice that I added in liblua5.1-filesystem0. Steve pointed out that there is a bug in liblua5.1-wsapi-fcgi-0. It doesn’t include it as a dependency. He reported this as a bug here, and it was fixed in liblua5.1-wsapi-fcgi-1.

 Install spawn-fcgi
If you’re running Debian testing you may be able to get spawn-fcgi through the distribution, however, I just downloaded it and compiled from source.
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -xzvf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3.tar.gz
./configure
make
make install

 Create a FastCGI Socket
spawn-fcgi -F 4 -u www-data -s /var/run/nginx-fcgi.sock -P /var/run/nginx-fcgi.pid — /usr/bin/wsapi.fcgi
For the sake of simplicity, we will just spawn it manually for now. If you’re feeling crafty you can add the above line to the start condition in/etc/init.d/nginx, and the line below to the stop condition. You can add both of them to restart.
cat /var/run/nginx-fcgi.pid | xargs -n 1 kill

 Create a lua file in /var/www/nginx-default/
 In this tutorial, use hello.lua. You can change this to whatever, you want but just make sure you make the modification in the nginx configuration below as well.

 Edit /etc/nginx/sites-available/default
Now let’s add the code that will point nginx to the correct file. For simplicity, we will simply point it to hello.lua. You can change this to anything, or simply modify the code to accept any *.lua file, as seen in the tutorial listed above. Here is the top of my default file:
listen   8081 default;
server_name  localhost;
access_log  /var/log/nginx/localhost.access.log;
location / {
    fastcgi_pass    unix:/var/run/nginx-fcgi.sock;
    fastcgi_param   SCRIPT_FILENAME “/var/www/nginx-default/hello.lua”;
    fastcgi_param   PATH_INFO       $request_uri;
    fastcgi_param   QUERY_STRING    $query_string;
    fastcgi_param   REQUEST_METHOD  $request_method;
    fastcgi_param   CONTENT_TYPE    $content_type;
    fastcgi_param   CONTENT_LENGTH  $content_length;
}

Restart nginx
/etc/init.d/nginx restart

Visit http://localhost:8081/
Congratulations! You should now see hello.lua.
 
If you have any problems, post in the comments. Stay tuned for

推荐阅读
  • 构建LNMP架构平台
    LNMP架构的组成:Linux、Nginx、MySQL、PHP关于NginxNginx与apache的作用一样,都是为了搭建网站服务器,由俄罗斯人lgorsysoev开发,其特点是 ... [详细]
  • Server Installation for Jitsi Meet
    2019独角兽企业重金招聘Python工程师标准ServerInstallationforJitsiMeetThisdescribesconfiguringaserverji ... [详细]
  • Ubuntu简介Ubuntu(乌班图)是一个以桌面应用为主的Linux操作系统,其名称来自非洲南部祖鲁语或豪萨语的“ubuntu”一词,意思是“人性”、“我的存在是因为大家的存在” ... [详细]
  • 2018年人工智能大数据的爆发,学Java还是Python?
    本文介绍了2018年人工智能大数据的爆发以及学习Java和Python的相关知识。在人工智能和大数据时代,Java和Python这两门编程语言都很优秀且火爆。选择学习哪门语言要根据个人兴趣爱好来决定。Python是一门拥有简洁语法的高级编程语言,容易上手。其特色之一是强制使用空白符作为语句缩进,使得新手可以快速上手。目前,Python在人工智能领域有着广泛的应用。如果对Java、Python或大数据感兴趣,欢迎加入qq群458345782。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • MACElasticsearch安装步骤及验证方法
    本文介绍了MACElasticsearch的安装步骤,包括下载ZIP文件、解压到安装目录、启动服务,并提供了验证启动是否成功的方法。同时,还介绍了安装elasticsearch-head插件的方法,以便于进行查询操作。 ... [详细]
  • Oracle分析函数first_value()和last_value()的用法及原理
    本文介绍了Oracle分析函数first_value()和last_value()的用法和原理,以及在查询销售记录日期和部门中的应用。通过示例和解释,详细说明了first_value()和last_value()的功能和不同之处。同时,对于last_value()的结果出现不一样的情况进行了解释,并提供了理解last_value()默认统计范围的方法。该文对于使用Oracle分析函数的开发人员和数据库管理员具有参考价值。 ... [详细]
  • LVS实现负载均衡的原理LVS负载均衡负载均衡集群是LoadBalance集群。是一种将网络上的访问流量分布于各个节点,以降低服务器压力,更好的向客户端 ... [详细]
  • 目录浏览漏洞与目录遍历漏洞的危害及修复方法
    本文讨论了目录浏览漏洞与目录遍历漏洞的危害,包括网站结构暴露、隐秘文件访问等。同时介绍了检测方法,如使用漏洞扫描器和搜索关键词。最后提供了针对常见中间件的修复方式,包括关闭目录浏览功能。对于保护网站安全具有一定的参考价值。 ... [详细]
  • 本文介绍了在无法联网的情况下,通过下载rpm包离线安装zip和unzip的方法。详细介绍了如何搜索并下载合适的rpm包,以及如何使用rpm命令进行安装。 ... [详细]
  • 负载均衡_Nginx反向代理动静分离负载均衡及rewrite隐藏路径详解(Nginx Apache MySQL Redis)–第二部分
    nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解 ... [详细]
  • 初探PLC 的ST 语言转换成C++ 的方法
    自动控制软件绕不开ST(StructureText)语言。它是IEC61131-3标准中唯一的一个高级语言。目前,大多数PLC产品支持ST ... [详细]
  • 如何查看电脑系统版本_腾讯云服务器系统版本怎么看?Windows和Centos版本怎么选?...
    腾讯云服务器系统版本怎么看?想要知道自己的腾讯云服务器系统版本是哪个,可以登录云服务器后台管理系统查看,或者使用命令行查询,如果不会操作& ... [详细]
  • 下载地址http:www.kbengine.org这货不错安装在Linux上安装(CentosDebianUbuntuetc.)服务端,请在终端输入:pythonkbenginek ... [详细]
  • 一、安装软件包dig和nslookup需要安装相关软件包。Centos:yuminstallbind-utilsDebian:apt-getupdate ... [详细]
author-avatar
我是来工作的程_586
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有