lighttpd interview questions
Top lighttpd frequently asked interview questions
When I start Apache Bench test:
ab -n 10000 -c 1300 http://domain.com/test.php
I get error:
socket: Too many open files (24)
When i change to '-c 1000' it works fine.
Because I can have more than 1000 concurrent users I would like to fix socket too many open files problem or increase parameter. How to do this and where?
I use lighttpd on centos 5.
Source: (StackOverflow)
I've just installed lighttpd on my dedicated server, mod_fastcgi is enabled, so I've appended the following lines to the lighttpd.conf
file:
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi"
)
)
)
But it still doesn't help, since I'm getting the 403 - Forbidden
message when I try to enter a PHP file in my web browser... When I delete the index.php
file from my web root directory and place the index.html
there, then everything is fine, and there are no errors, no matter if index.php
file has 100 lines or just one - <?php echo 'test'; ?>
it always is showing up an 403 - Forbidden
, I'm out of ideas now.
Why does it happend?
ls -la
of my web root directory:
#
total 6
drwxr-xr-x 15 root wheel 1536 Jul 18 10:23 .
drwxr-xr-x 4 root wheel 512 Jul 18 08:45 ..
drwxr-xr-x 2 www www 512 Jul 1 02:36 cache
drwxr-xr-x 2 www www 512 Jul 1 02:36 config
drwxr-xr-x 6 www www 512 Jul 1 02:36 inc
-rw-r--r-- 1 www www 9 Jul 18 11:02 index.php
Source: (StackOverflow)
I'm developing a CherryPy FastCGI server behind lighttpd with the following setup to enable using ORM SQLAlchemy sessions inside CherryPy controllers. However, when I run stress tests with 14 concurrent requests for about 500 loops, it starts to give errors like AttributeError: '_ThreadData' object has no attribute 'scoped_session_class'
in open_dbsession()
or AttributeError: 'Request' object has no attribute 'scoped_session_class'
in close_dbsession()
after a while. The error rate is around 50% in total.
This happens only when I run the server behind lighttpd, not when it's run directly through cherrypy.engine.start()
. It's confirmed that connect()
isn't raising exceptions.
I also tried assigning the return value of scoped_session
to GlobalSession
(like it does here), but then it gave out errors like UnboundExceptionError
and other SA-level errors. (Concurrency: 10, loops: 1000, error rate: 16%. Occurs even when run directly.)
There are some possible causes but I lack sufficient knowledge to pick one.
1. Are start_thread
subscriptions unreliable under FastCGI environment? It seems that open_dbsession()
is called before connect()
2. Does cherrypy.thread_data
get cleared for some reason?
server code
import sqlalchemy as sa
from sqlalchemy.orm import session_maker, scoped_session
engine = sa.create_engine(dburi, strategy="threadlocal")
GlobalSession = session_maker(bind=engine, transactional=False)
def connect(thread_index):
cherrypy.thread_data.scoped_session_class = scoped_session(GlobalSession)
def open_dbsession():
cherrypy.request.scoped_session_class = cherrypy.thread_data.scoped_session_class
def close_dbsession():
cherrypy.request.scoped_session_class.remove()
cherrypy.tools.dbsession_open = cherrypy.Tool('on_start_resource', open_dbsession)
cherrypy.tools.dbsession_close = cherrypy.Tool('on_end_resource', close_dbsession)
cherrypy.engine.subscribe('start_thread', connect)
lighttpd fastcgi config
...
var.server_name = "test"
var.server_root = "/path/to/root"
var.svc_env = "test"
fastcgi.server = (
"/" => (
"cherry.fcgi" => (
"bin-path" => server_root + "/fcgi_" + server_name + ".fcgi",
"bin-environment" => (
"SVC_ENV" => svc_env
),
"bin-copy-environment" => ("PATH", "LC_CTYPE"),
"socket" => "/tmp/cherry_" + server_name + "." + svc_env + ".sock",
"check-local" => "disable",
"disable-time" => 1,
"min-procs" => 1,
"max-procs" => 4,
),
),
)
edits
- Restored the missing
thread_index
argument in the code example from the original source code (thanks to the comment)
- Clarified that errors do not occur immediately
- Narrowed down the conditions to lighttpd
Source: (StackOverflow)
I'm running Django on Linux using fcgi and Lighttpd. Every now and again (about once a day) the server just dies. I'm using the latest stable release of Django, Python and Lighttpd.
The only thing I can think of is that my program is opening a lot of files and executing a lot of external processes, but I'm fairly sure that side of things is watertight.
Looking at the error and access logs, there's nothing exceptional happening (i.e. load isn't above normal). On those occasions where I have had exceptions from Python, these have shown up in the error.log, but when this crash happens I get nothing.
Is there any way of finding out why the process died? Short of putting logging statements on every single line? Obviously I can't reproduce this so I don't know exactly where to look.
Edit
It's the django process that's dying. I'm running the server with manage.py runfcgi daemonize=true method=threaded host=127.0.0.1 port=12345
Source: (StackOverflow)
Is there any way to automatically minify static content and then serve it from a cache automatically? Similar to have mod_compress/mod_deflate work? Preferably something I could use in combination with compression (since compression has a more noticeable benefit).
My preference is something that works with lighttpd but I haven't been able to find anything, so any web server that can do it would be interesting.
Source: (StackOverflow)
Possible Duplicate:
I never really understood: what is CGI?
In the lighttpd config, we define two paths (as shown below), one of them is the binary of PHP, the other is the socket path. My question is, in which point does the lighttpd fetches the final HTML output created by PHP? Does the binary give an output to lighttpd as a response? Or does it create a temporary file in another place and server fetches it?
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
)))
Source: (StackOverflow)
In order to lighten Apache's load people often suggest using lighttpd to serve up static content.
e.g. http://www.linux.com/feature/51673
In this setup Apache passes requests for static content back to lighttpd via mod_proxy, while serving dynamic requests itself.
My question is: how does this reduce the load on the server? Since you still have an apache process spawned for every request that comes in, how does this positively impact the load? From what I can see the size of the Apache process proxying its request through lighttpd is as large as it would be if it were serving the file itself.
Source: (StackOverflow)
Well, I'm wondering if theres a way to run both rails and PHP on Lighty, on Ubuntu. I want to run both my PHP projects and Rails projects on the one server/domain.
I have little experience with Linux really, so forgive my naivety.
If theres a way of doing this please let me know :)
Source: (StackOverflow)
I've written a website in node.js and express. Now I configured lighttpd to use the node.js server with an subdirectory:
$HTTP["url"] =~ "^/app/" {
proxy.server = ( "" => ( (
"host" => "127.0.0.1",
"port" => 3000
) )
)
}
When I open http://localhost/app/
I get error 404 because I wrote something like this:
app.get('/', function (req, res){
res.render('index');
});
Is there a better way as modifying these lines like:
var relPath = '/app';
app.get(relPath + '/', function (req, res){
res.render('index');
});
?
Source: (StackOverflow)
I have a website hosted on lighttpd, accessible at the "www" subdomain. I also have a chat server listening on port 8124 made with node.js and socket.io.
I want all client traffic to happen on port 80, by redirecting all requests to the "chat" subdomain to port 8124. So I enabled mod_proxy and in lighttpd.conf I added:
$HTTP["host"] == "chat.myserver.com" {
proxy.server = (
"" => ((
"host" => "78.128.79.192",
"port" => "8124"
))
)
}
On the client, when I connect to the websocket,
var socket = io.connect('http://chat.myserver.com');
I get the right messages from node.js:
debug - client authorized
info - handshake authorized 6067470561567883577
debug - setting request GET /socket.io/1/websocket/6067470561567883577
debug - set heartbeat interval for client 6067470561567883577
debug - client authorized for
debug - websocket writing 1::
But the browser gives an error:
Firefox can't connect to server ws://chat.myserver.com/socket.io/1/websocket/6067470561567883577
Of course, everything works correctly if I connect directly to the port 8124:
var socket = io.connect('http://www.myserver.com:8124');
But, as I said, I would like all client traffic to be on port 80. Is it possibile?
Source: (StackOverflow)
I'm setting up lighty according to this guide, and I don't really have an use for the lighttpd daemon that was installed (this is the one that resides in /etc/init.d/lighttpd). I don't want a webserver running all the time, except when I'm working. I want to just call lighttpd -Df lighttpd.conf when I need to.
How can I disable this ?
Source: (StackOverflow)
I have this scenario:
A user comes to my site and followes a link, wich doesnt exists anymore, he should be redirected to a custom errorpage. (that works)
If a user does something, that throws an error, he should see the Stacktrace and the real Errorpage.
This is my current Web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors>
<error statusCode="404" redirect="/errors/404.htm" />
</customErrors>
<compilation debug="true" strict="false" explicit="true" />
</system.web>
</configuration>
with this configuration, a 404 will be redirected to the right site, but a HTTP 500 will be shown as following:
Server Error in '/' Application
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web [.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
[...]
But in this case i want to show the stacktrace.
How can i do this?
Note: We're on Linux with a Mono <- FastCGI -> Lighttpd construction.
Source: (StackOverflow)
I recall a very fast kernel module for Linux called "TUX" for static files to answer IIS's superior-to-Linux static file web-serving performance and solve the "C10K problem." Now I keep seeing:
- Nginx
- Lighttpd
- CDNs
... for "fast static file-serving." Serving static files quickly isn't difficult if your OS has the right features. Windows has since the invention of IO Completion ports, overlapped I/O, etc.
Did Tux die because of the security implications? Was it an experiment that Kqueue/Epoll combined with features like Sendfile made obsolete? What is the best solution to serve 100% static content -- say packshots of 50 or so images to simulate a "flipbook" movie.
I understand this ia "Server-related" question, but it's also theoretical. If it's purely static, is a CDN really going to be better anyway?
Source: (StackOverflow)