using .asmx using lighttpd and mono fastcgi - asp.net

I have deployed a web service to a ubuntu server running lighttpd and fastcgi-mono-server2. The .asmx page loads correctly but when I test the method I get a 404.
My web service is called Import.asmx and my method is called download and the 404 comes back saying import.asmx/download does not exist
Using xsp2 the same service works perfectly
I assume it is something to do with how the /download gets served by lighttpd/fastcgi but cannot work out how to fix it.

Solved the 404 error... but now I have a 500.
Actually I was getting this error on every MyService.asmx/SomeMethod post calls. The solution [NOT REALLY] I've figured it out:
location ~ \.(aspx|asmx|ashx|asmx\/(.*)|asax|ascx|soap|rem|axd|cs|config|dll)$ {
fastcgi_pass 127.0.0.1:9001;
index index.html index.htm default.aspx Default.aspx;
fastcgi_index Default.aspx;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
I've change it from only asmx to asmx/()*. Ok no 404 but now a 500: System.Web.HttpException: Method 'POST' is not allowed when accessing file '/Services/MyService.asmx/MyMethod'.
This findings give me some clues that nginx don't handle properly this kind of requests. After googling for almost 2 hours I've found a solution:
location ~ \.asmx(.*) {
fastcgi_split_path_info ^(.+\.asmx)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include /etc/nginx/fastcgi_params;
fastcgi_index Default.aspx;
fastcgi_pass 127.0.0.1:9001;
}
I wasn't to far from it. Just add this location rule before the current you have and works fine.

I had the very same issue. Turned out to be default directive for serving 404 when not finding assets. Removed the following line:
try_files $uri $uri/ =404;
And add PATH_INFO as fastcgi param in /etc/nginx/fastcgi_params:
fastcgi_param PATH_INFO $fastcgi_path_info;
That fixed it for me. Hope it helps.

Related

Nginx, location, alias and php

We are moving from lighttpd to nginx for HTTP/2.0 and having hard time configuring something which was so simple in lighttpd.
alias.url = ("/api" => "/web/myserver.com/develapi/")
We do this as we version control api and then just point url to appropriate folder. We do not want to use file links as well. Moreover, it's an one line command in lighttpd.
Here is how we are trying to achieve the same in NGINX.
location /api {
alias /web/myserver.com/develapi;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
}
However, this does not work as nginx passes /web/myserver.com/develapi as $document_root and /api/index.php as $fastcgi_script_name and hence resulting SCRIPT_FILENAME is wrong.
We then tried to use root
location /develapi {
root /web/myserver.com;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
}
This works as nginx passes /web/myserver.com as $document_root and /develapi/index.php $fastcgi_script_name and hence resulting SCRIPT_FILENAME is correct.
However, using root means either we have change existing structure or url. For this situation, using alias is the right solution but the way nginx implementing it, makes it tricky to use alias.
May be we are missing something trivial, any pointers will be appreciated.
I think problem is commonly answered/documented way to return SCRIPT_FILENAME
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Reading more docs reveals $request_filename is a better way to go and works in both root and alias
fastcgi_param SCRIPT_FILENAME $request_filename;
It has been 3+ years... hope you have found the answer by now!
Here is a solution, for similar problem where I wanted to rewrite the fastcgi_script_name stripping off "wiki/" in front of them.
location /wiki {
alias C:/opt/mw/mediawiki-1.36.1;
index index.html index.php index.htm;
location ~ ^/wiki(/.*\.php(?:\?.*)?)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$1;
include fastcgi_params;
}
}
Got the inspiration from: How to remove a path segment from NGiNX fastcgi_script_name?

install postfixadmin in a subfolder of a domain in nginx

I need to install postfixadmin as a subfolder of a domain hosted in nginx.
In other words, I'm trying to access postfixadmin using http://example.com/postfixadmin
Physically, the contents of the sites are stored this way:
example.com site in /var/www/example
Postfixadmin files in /var/www/postfixadmin
I've tried adding this within the server section of example.com:
location ~ /posfixadmin/ {
root /var/www;
index index.php;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
The above works partially, php scripts are executed correctly, but css and image files found under /var/www/postfixadmin/css and /var/www/postfixadmin/images are not loaded.
I've checked at the generated html code and the links to css and image files in postfixadmin are called using relative paths, like this:
href="css/default.css"
I think nginx tries to get the css files from http://example.com/css instead of http://example.com/postfixadmin/css, that's why it's failing, I've tried something like this:
location /postfixadmin/css/ {
root /var/www/postfixadmin;
}
but the above doesn't work.
Any idea about how to fix this? Thanks in advance!
I know it's an old topic, but still: do not use "root" in a "location" block. Source: https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
This works for me at the moment with the current PostfixAdmin 3.2 (which moved all the public facing stuff into the "public" subdirectory). Mind that I have defined the fastcgi_pass elsewhere, so this bit is not directly applicable.
location /postfixadmin {
alias /usr/local/www/postfixadmin/public;
location ~ ^(.+\.php)(.*)$ {
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_read_timeout 180;
fastcgi_buffers 4 256k;
fastcgi_buffer_size 128k;
}
location ~ \.php {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass php;
fastcgi_index index.php;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

403 Forbidden error in phpmyadmin

I am trying to run rails application on ubuntu14.04 , after installing phpMyAdmin , nginx unable to load phpmyadmin
nginx error log
nginx/html/phpmyadmin/" is forbidden
Within your Nginx conf.d folder (For Ubuntu location is /etc/nginx/conf.d) create one default.conf file if not already available and put the below code block. Sample conf file you can check here. You can use the server block to begin with.
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

What is fastcgi_index in nginx used for?

On many sites can be found this nginx location block :
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
...
}
Given the official documentation of fastcgi_index, it seems like it is used when requests end with /. However, it doesn't match the regular expression of the location block above? Am I missing something about the fastcgi_index directive?
You are right, if your nginx configuration (outside the location directive) has no index directive, then the location directive will never match and the fastcgi_index directive is useless.
If you have a line like this on your configuration
index index.php
then a request to / will create an internal redirect to /index.php, the location will match and fastcgi will be called. php-fpm will need a SCRIPT_FILENAME parameter that points to the file being executed. Normally, the configuration looks something like this:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
$fastcgi_script_name contains the name of the matched script, so fastcgi_index is ignored.
There is at least one instance where fastcgi_index is useful and used: when nginx and php-fpm are on different servers and nginx can't match the index.php file.

NGINX location rewrite

Given the URL below, how can I have NGINX automatically pass the last part of the URL (not the GET Params but the last chunk of the base URL - myMap) to fastcgi_param SCRIPT_FILENAME?
The URL:
http://localhost/mapserver/myMap?&LAYERS=base....
NGINX config:
location /mapserver/ {
fastcgi_pass unix:/tmp/mapserver.sock;
fastcgi_index mapserv?*;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/mapserv?map=/mapfiles/myMap.map;
include fastcgi_params;
}
Thanks.
The documentation states that you can use variables in fastcgi_param values :
Sets a parameter that should be passed to the FastCGI server. The value can contain text, variables, and their combination. These directives are inherited from the previous level if and only if there are no fastcgi_param directives defined on the current level.
So you can use a location with a regular expression and a capture group :
location ~ /mapserver/(.*)$ {
fastcgi_pass unix:/tmp/mapserver.sock;
fastcgi_index mapserv?*;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/mapserv?map=/mapfiles/$1.map;
include fastcgi_params;
}
Be aware that this kind of location has a particular priority during request processing.

Resources