I am trying to execute cgi script on Nginx. In nginx.conf file, I added a location directive such as below:
location /cgi-bin{
root cgi-bin;
index index.cgi;
}
When I try to connect to http://example.com/cgi-bin/index.cgi, it says file not found. In error.log, I see the request as "http://example.com/html/cgi-bin/index.cgi.
cgi-bin is not in html folder. The correct path is "http://example.com/cgi-bin/index.cgi
I tried many possibilities for location directive. Either it looks in html/cgi-bin or it does /cgi-bin/cgi-bin/index.cgi. I am not sure why it uses 'cgi-bin' twice
Any suggestions.. I have been trying for hours now!!!
Related
I have these lines in my nginx config:
location /proxy {
proxy_pass http://mysite.ru/;
proxy_redirect http://localhost/app http://mysite.ru/app;
}
Css files from mysite.ru are located in app folder, but it can't be loaded because full path to css file is like this: http://mysite.ru/app/files/css/style.css and it hasn't proxy in path, so it's trying to load http://localhost/app/files/css/style.css, and in the second line I'm trying to redirect this, but nothing works, what means that I'm doing something wrong (I don't know much about Nginx, what I'm trying is to understand)
I have a config that looks like:
server {
listen 80;
root /pubStuff;
...stuff...
location /something {
root /app/something
}
}
The intention is, that while I can access stuff in the door of the server using example.com/ or with whatever directory/files location in /pubStuff, IF someone were to request example.com/something, or example.com/something/something.here.zip, they would get it!
When I try to go for example.com/something, I get a 404 not found error!
In error log it says:
14#14: *15409 open() "/app/something/something" failed (2: no such file or directory)....
I dont understand why does it affix a second "something", when I asked for only example.com/something, which should show me the content of /app/something as configured above, right?
I read the documentation on http://nginx.org/en/docs/http/ngx_http_core_module.html#location but it is rather focused on the prefix matching stuff, not explaining whats wrong in my use case.
Based on stackoverflow suggestions, I tried the solution at Nginx -- static file serving confusion with root & alias
basically, it seems that only should only specify root /app/, and that it would go to /app/something/something.zip, but error log says it tries /pubStuff/something/something.zip, totally ignoring the root directive for /something.
How can I read a file within location directive? After reading the file, based on some decision I will proceed further or throw error.
I am new to Nginx but I managed to install Drupal on windows 8 machine. I just noticed that this URL(http://localhost:8080/drupal/) spits out error message 403 Forbidden. If I mutate that URL a bit by including the index(http://localhost:8080/drupal/index.php) file then it works as expected. My question is this:
How could I configure Nginx so that I wont get error message when I go to http://localhost:8080/drupal/?
Depending on your configuration, an index directive will encourage nginx to look for specific files when encountering a directory:
index index.php;
For a more specific rule, to single out that one path and map it to the controller, you could use an exact match location directive:
location = /drupal/ { rewrite ^ /drupal/index.php last; }
See this and this for more.
I need to know about full downloading a resource from server. My server is configured with NginX web server, and I want to do something if and only if the resource downloaded completely by user.
If you are using Nginx to handle downloading your files (using XSendfile), you should add a specific access_log block to your download handling block in your Nginx configs (in your "server" block). It would be something like this:
location /download_music/ {
internal;
root /usr/share/nginx/MY_SITE/media/music;
access_log /var/log/nginx/download.MY_SITE.log download;
}
The word "download" at the end of the access_log line is actually a log format which you should add it to the nginx main config file (/etc/nginx/nginx.conf) in the "http" block. It could be something like this:
http {
...
log_format download '{ "remote_addr" : "$remote_addr", "time":"$time_local", "request":"$request", '
'"traffic":$body_bytes_sent, "x_forwarded_for":"$http_x_forwarded_for" }';
...
}
You can change this format to what format you want (you will use it in your script later). If you monitor this log file (using "tail -f /var/log/nginx/download.MY_SITE.log") you will see that any time a download is paused or finished, a line of log will be added to this file.
The next step is using rsyslog and the "imfile" and "omprog" modules. You should add these configs at the end of the config file of rsyslog (/etc/rsyslog.conf):
$ModLoad imfile
$InputFileName /var/log/nginx/download.MY_SITE.log
$InputFileTag nginx-access
$InputFileStateFile state-nginx-access
$InputFileSeverity info
$InputFileFacility local3
$InputFilePollInterval 1
$InputRunFileMonitor
$ModLoad omprog
$actionomprogbinary /usr/share/nginx/MY_SITE/scripts/download.py
$template LogZillaDbInsert,"%hostname:::lowercase%\9%pri%\9%programname%\9%msg%\n"
local3.* :omprog:;RSYSLOG_TraditionalFileFormat
Pay attention to this line:
/usr/share/nginx/MY_SITE/scripts/download.py
This is the address of the script which would be called every time a log entry is added to the log file and the whole log entry will be available in this script using (in Python code):
line = sys.stdin.readline()
Then you can parse the line and find whatever you have logged including the downloaded file size (on every pause/finish event). Now, you can simply include the file size in the download URL and retrieve it in this script and compare it with the downloaded bytes. If these two numbers are equal, it means that download has been finished successfully. Moreover, you can do any other thing you want in this script (for example, expire download link, increase download count on DB, ...)