I am very new to nginx and lua .i have installed Openresty .
below is my code in nginx.conf file .
server{
location /hellolua {
default_type 'text/plain';
content_by_lua ' local name = ngx.var.arg_name or "Anonymous"
ngx.say("Hello, ", name, "!") ';
}
}
When i am running sudo service nginx start i am getting error Starting nginx: nginx: [emerg] unknown directive "content_by_lua" in /etc/nginx/nginx.conf:24
nginx: configuration file /etc/nginx/nginx.conf test failedt
Please let me know what i am missing .
It seems to me, as if you haven't installed the right module? ngx_lua (http://wiki.nginx.org/HttpLuaModule)
You mention OpenResty. Did you configure it with lua? If not, the guide is here(http://wiki.nginx.org/HttpLuaModule#Installation).
Quick resumé:
The ngx_openresty bundle can be used to install Nginx, ngx_lua, either one of the standard Lua 5.1 interpreter or LuaJIT 2.0, as well as a package of powerful companion Nginx modules. The basic installation step is a simple ./configure --with-luajit && make && make install.
You can manually compile ngx_lua into nginx too, the full guide is in the link too.
After comment-discussing - I removed the irrelevant part of the answer.
By default, OpenResty's nginx is installed into the path /usr/local/openresty/nginx/sbin/nginx. Your system's default nginx init configurations need an update to point to the right locations.
Related
I'm trying to install certbot. I'm using Centos8 and following instructions from https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-centos-8
The error occurs when I run sudo certbot --nginx The error I get is:
The nginx plugin is not working; there may be problems with your existing config uration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary.
Ensure nginx exists, the binary is executable, and your PATH is set correctly.",)
I want to deploy a little Flask webapp on a root cloud server with Plesk installed. I followed this tutorial as it uses Nginx and Gunicorn, like proposed by the developer of Flask: Miguel Grinberg.
The problem is that Plesk has a modified variant of nginx pre-installed named sw-nginx and I've absolutely no clue on how to implement that line of code:
server {
listen 80;
server_name my.subdomain.com;
location / {
include proxy_params;
proxy_pass http://unix:/var/www/vhosts/mydomain.com/my.subdomain.com/myproject/app.sock;
}
}
If I just put in in a .conf file, the configtest of Nginx fails:
$ nginx -t
nginx: [emerg] open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/conf.d/myproject.conf:6
nginx: configuration file /etc/nginx/nginx.conf test failed
Maybe the syntax of the proxy_pass value is wrong (I tried many, here I put one of them), or maybe the proxy_pass param isn't supported or has to be implemented somewhere else?
PS: I also found this answer How to deploy Flask project on Plesk subdomain
But I read somewhere, that replacing sw-nginx by the standard nginx wouldn't be supported by Plesk. Don't want to break anything...
Thanks for your help.
I am trying to implement "ssl_preread" in my nginx. My nginx is compiled with "--with-stream_ssl_preread_module" this module.
I mentioned "ssl_preread on;" in server directive of nginx.conf. But i am getting below error.
nginx: [emerg] "ssl_preread" directive is not allowed here in /opt/nginx/conf/nginx.conf:43
I am following below doc.
http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html
Compile with both modules
--with-stream
--with-stream_ssl_preread_module
Create a stream block outside http block
stream {
upstream app {
server IP1:Port;
server IP2:Port;
}
map $ssl_preread_server_name $upstream {
default app;
}
server {
listen PORT;
ssl_preread on;
proxy_pass $upstream;
}
}
This worked for me. Let me know if this works for you too
Maybe U need to update Nginx to lastest version. 1.10 I meet this error too, but 1.18 the config is OK.
Perhaps this is a late answer. I had the following issue when installing nginx 1.14 from CentOS 8.3 repo.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] unknown "ssl_preread_server_name" variable\nnginx: configuration file /etc/nginx/nginx.conf test failed\n',)
The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] unknown "ssl_preread_server_name" variable\nnginx: configuration file /etc/nginx/
nginx.conf test failed\n',)
I fixed it by upgrading the very latest nginx-1:1.20.0-1.el8.ngx.x86_64, following this URL
http://nginx.org/en/linux_packages.html#RHEL-CentOS
So I was trying some settings of the Nginx PageSpeed module, but there was two settings that I couldn't set for some reason.
pagespeed NumRewriteThreads 2;
pagespeed NumExpensiveRewriteThreads 2;
For some reason these two settings always throw error when I try to restart or test my nginx config.
sudo service nginx restart
[FAIL] Restarting nginx: nginx failed!
When I test the file I get this:
"pagespeed" directive "NumRewriteThreads" not recognized or too many arguments in /etc/nginx/nginx.conf:40
nginx: configuration file /etc/nginx/nginx.conf test failed
My Nginx version is the following:
sudo /usr/sbin/nginx -v
nginx version: nginx/1.6.0
The settings appear in the PageSpeed docs as well, so I'm wondering if there's something I am missing to make them work.
https://developers.google.com/speed/pagespeed/module/system#tune_thread
I've entered a bug for this: ngx_pagespeed #728. I think it's just an oversight.
I am having a website which is working on nginx already .
nginx conf file is in /etc/nginx.conf folder.
Now i want to integrate lua into that project so i installed Openresty .
I created a folder with name "work" as per instruction in doc .And website is working fine at port 8080 as per instructions.
Now i want to use same code into my /etc/nginx/nginx.conf file.
like i can use statements like 'content_by_lua ' there .
I am not able to configure this .
I am getting below error.
Starting nginx: nginx: [emerg] unknown directive "content_by_lua" in /etc/nginx/nginx.conf:25
nginx: configuration file /etc/nginx/nginx.conf test failed
Let me know what i am doing wrong
I started from the same point. Had nginx, had lua, installed openresty and went from there. I was getting the exact same error. After spending considerable time, trying to make the openresty packages play nice with my nginx installation, I found it easiest to uninstall nginx and move forward just with openresty's nginx. Just make backups of your current nginx.conf and any vhost files.
When installing openresty I was sure to include the --with-luajit option. Set up a "hello, world" test, and everything worked wonderfully. My biggest complaint was not being able to start and stop nginx as a service anymore. The issue is a lack of init.d file in the openresty installation. Luckily I ran across this:
https://groups.google.com/forum/#!topic/openresty-en/7UOz-y77CY4
just change the name to openresty (instead of openresty.init.d) and place in /etc/init.d/ (assumed for Ubuntu). and start/stop/reload as sudo service openresty start
The error shows that your nginx don't compiled with the right module.
try type nginx -V to see if your nginx configured with nginx_lua_module
Maybe you should find out where the openresty nginx is and use this nginx instead of the default one.