I've built nginx from sources with lua support and I'm able to run server-side scripts like this:
http {
lua_package_path '/usr/local/share/lua/5.1/?.lua;;';
server {
listen 80;
location /hi {
content_by_lua '
ngx.header["Content-Type"] = "text/plain;charset=utf-8"
ngx.say("Hello world!")
--local s = require("socket")
ngx.say(_VERSION);
';
}
}
}
So when I access http://localhost/hi, I get this output:
Hello world!
Lua 5.1
If I uncomment line local s = require("socket") then I get following error in my browser:
Unable to load page
Problem occurred while loading the URL http://localhost/hi
Connection terminated unexpectedly
soucket.lua presents in this folder:
root#debian:/usr/local/share/lua/5.1# ls
ltn12.lua mime.lua socket socket.lua
UPDATE: adding cpath doesn't help:
lua_package_cpath '/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/socket/?.so;;';
# ls /usr/local/lib/lua/5.1/socket/*.so
/usr/local/lib/lua/5.1/socket/core.so /usr/local/lib/lua/5.1/socket/serial.so /usr/local/lib/lua/5.1/socket/unix.so
# ls /usr/local/share/lua/5.1/
ltn12.lua mime.lua socket socket.lua
How can I fix/diagnose this problem?
Thanx
If the socket.lua is the diegonehab/luasocket,
then it requires socket/core.so
You need to specify the lua_package_cpath
cpath is for compiled shared library modules (.so), path is for text modules (.lua)
/usr/local/lib/lua/5.1/?.so - most common value for cpath
Do not try to use LuaSocket inside nginx. LuaSocket is a blocking library and nginx is non-blocking so you will have problems. Check out ngx.socket.tcp instead. Its API is compatible with socket.tcp but it is non-blocking.
Related
we got a new WebServer with CentOS, Plesk and php-fpm.
Now we don't get the php extension running.
What we did:
installed latest SQL Anywhere 17 (ebf29577)
copied php-7.3.0_sqlanywhere_r.so to /opt/plesk/php/7.3/lib64/php/modules/
loading php-7.3.0_sqlanywhere_r.so via /opt/plesk/php/7.3/etc/php.d/sqlanywhere.ini
this leads to an error:
WARNING: [pool plesk-php73-fpm.plesk-service.localdomain] child 11616 said into stderr: "NOTICE: PHP message: PHP Warning: request_startup() for sqlanywhere module failed in Unknown on line 0"
(This leads to php 7.3 fpm is not loading at all)
next try was to switch from FPM to CGI: same error
module is loadable itself within shell if LD_LIBRARY_PATH was enhanced with path /opt/sqlanywhere17/lib64/
some tries getting the cause by strace did not help
Has anybody an idea or maybe even successfully installed php extension.
Thanks
Florian
after a lot of tests we found a solution:
in Plesk Domain php settings we had to add:
[php-fpm-pool-settings]
env[LD_LIBRARY_PATH]="/opt/sqlanywhere_v2/lib64:$LD_LIBRARY_PATH"
Now all libs are found and it works
For me solution was, creating custom handler:
plesk bin php_handler --add -displayname "PHP SQLAnywhere 7.4" -path /opt/php-custom-handlers/7.4/php-sqlanywhere.fcgi -clipath /opt/plesk/php/7.4/bin/php -phpini /opt/plesk/php/7.4/etc/php.ini -type fastcgi
php-sqlanywhere.fcgi contents:
#!/bin/bash
LD_LIBRARY_PATH=/opt/sqlanywhere17/lib64
export LD_LIBRARY_PATH
exec /opt/plesk/php/7.4/bin/php-cgi "$#"
And finally using this handler on domain php settings and adding on additional directives:
extension=sqlanywhere.so
How can I get the absolute path of a file without hardcoding the path in a String?
So basically I'm asking for vert.x's version of PHP's $_SERVER['DOCUMENT_ROOT']. Does anybody know?
UPDATE
I have the following directory structure:
| app.coffee
| Views
-| foo.html
app.coffee:
vertx = require('vertx')
rm = new vertx.RouteMatcher()
rm.get '/', (req) ->
req.response.sendFile "Views/foo.html"
vertx.createHttpServer().requestHandler(rm).listen(8080)
It sounds like you are looking for the execution directory of the application. To get the execution directory you can just look up the system property 'user.dir' like so:
System.getProperty("user.dir")
So for instance when I serve static files in vertx for testing I use this:
val staticFilePath = container.config().getString("static_files", System.getProperty("user.dir"));
server.requestHandler(
{
request: HttpServerRequest => {
request.response().sendFile(staticFilePath + "/something.css")
}
}
If you are still not getting the desired result just print out the user.dir property to see where you are trying to serve files from.
References:
http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
Just type in a relative path, it will refer to the working directory you launched the vertx command into.
Look at this simple example:
$ ls
index.html verticle.scala
As you can see, I have a verticle and a static file in my (unspecified!) directory.
$ cat index.html
Hello!
$ cat verticle.scala
vertx.createHttpServer().requestHandler({ req: HttpServerRequest =>
req.response().sendFile("index.html") // <-- relative path!
}).listen(8080)
Now I just run it from here
$ vertx run verticle.scala
Compiling verticle.scala as Scala script
Starting verticle.scala
Succeeded in deploying verticle
And it just works, no need at all to specify constants like in PHP :)
$ curl localhost:8080
Hello!
Enjoy!
I bet you're trying to do
curl http://localhost:8080/foo.html
That can't work because your route matcher is configured to match / and respond with the contents of foo.html.
The right test case should be instead:
curl http://localhost:8080/
and the expected result should be
Hello!
Route matcher is not is the wrong tool for serving static files. If you intend to do that, refer to the web server module
UPDATE
Mate, this thing works for me in coffeescript too. What Vert.x version are you using?
$ vertx version
2.1 (built 2014-05-27 12:39:02)
$ cat app.coffee
vertx = require('vertx')
rm = new vertx.RouteMatcher()
rm.get '/', (req) ->
req.response.sendFile "Views/foo.html"
vertx.createHttpServer().requestHandler(rm).listen(8080)
$ vertx run app.coffee &
[1] 27731
$ Succeeded in deploying verticle
$ curl localhost:8080
ciao
$ cat Views/foo.html
ciao
I installed Composer and a SDK for Mailgun's service. These are the steps i followed:
# current directory
cd ~
# Install Composer
curl -sS https://getcomposer.org/installer | php
# Add Mailgun as a dependency
php composer.phar require mailgun/mailgun-php:~1.7
According to the instructions, all I did after that was (index.php):
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# First, instantiate the SDK with your API credentials and define your domain.
$mg = new Mailgun("key-my-key-goes-here-987654321");
$domain = "somedomain.com";
Then, I tried to get the list of bounced emails:
$data = $mg->get("$domain/bounces", array('limit' => 15, 'skip' => 0));
var_dump($data);
...and I'm getting this error:
Warning: require(vendor/autoload.php): failed to open stream: No such
file or directory in /var/www/html/index.php on line 2 Fatal error:
require(): Failed opening required 'vendor/autoload.php'
(include_path='.:/usr/share/pear:/usr/share/php') in
/var/www/html/index.php on line 2
So I'm guessing it has something to do with composer's installation/configuration perhaps? Thanks for any help...
The way you programmed it, you must have the following files all in the same directory:
composer.json
index.php (your test script)
And you must have run the composer require command while being inside this directory. This will also create a directory named vendor here, and add plenty of files, amongst them vendor/autoload.php.
If however your test script isn't in this location, the require call will not find the file where you tell PHP to find it. This isn't any failure of Composer, but simply the fact that you have to include that file according to your situation, not by copy&paste code. If you change the path of your test script, you have to change the path of the vendor directory as well.
I have a web application which I test locally and deploy on EC2 instance
I am using local nginx configuration which looks like as
location /static/ { alias /home/me/code/p/python/myapp/static/;
# if asset versioning is used
if ($query_string) {
expires max;
}
} location /templates/ { alias /home/me/code/p/python/app/templates/;
# if asset versioning is used
if ($query_string) {
expires max;
}
}
On EC2 instance, the only thing that would change is the path, e.g.
/home/me/code/p/python/myapp/static/ to /User/ubuntu/code/p/python/myapp/static/
To make this happen I change the configuration to look like
~/code/p/python/myapp/static/
but this didn't work, it shows the path
/etc/nginx/~/code/p/python/myapp/static/
which is not right
Question
- Is it possible to include environment variables in nginx conf?
What I want
- Nginx conf, which can read variables on specific machines to create paths, so that I don't have to change it per machine and code is reusable
Thank you
Two ways of doing this:
As suggested above, symlinking is a really good way of making paths match on machines, while keeping code in one place. A symbolic link basically is an alias; if /link is a symlink for /file, when you ask for /link, you'll get /file.
ln -s /file /link
Using include statements. In nginx, you can include variables.conf;. E.g.
nginx.conf:
include variables.conf
...
http {
listen $port;
...
}
variables.conf:
set $foo "Something";
set $bar "Else";
set $port 80;
i try to get the following code to run:
class common
{
...
# common packages
package
{
["lsb-release", "figlet"]: ensure => installed,
}
# Print some information if someone logs in:
file { "/etc/motd":
#require => [ Package["figlet"], File["/usr/bin/figlet"] ],
require => Package["figlet"],
content => generate('/usr/bin/env', '/usr/bin/figlet','-w', '186', '-p', '-f', 'banner', "$hostname"),
}
....
}
should't this work?
i get the following error:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to execute generator /usr/bin/env: Execution of '/usr/bin/env /usr/bin/figlet -w 186 -p -f banner hostname' returned 127: /usr/bin/env: /usr/bin/figlet: No such file or directory
at /etc/puppet/modules/common/manifests/init.pp:37 on node puppetmaster.local
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
first i had no require (row 12) and no package (row 5-8) in the code, to fix the errors i thought to i can simply add the row 12 (require package figlet) but it does not work. so i added the package figlet, but the the error does not go away.
how to add this dependency? shouldn't puppet run through the code and don't skip the run totally?
generate() runs on the server, not the client. (It's a parser function so it has to run on the server)
The class as you've written it will ensure that clients get figlet installed on them, but then tries to run figlet on the puppetmaster. Just install figlet on your puppetmasters and you won't need the package resources.
Also use smslant font, not banner :)