-1

I have nginx running on Linux. I want to take an .aspx webpage and output just the html from it (no <% %> directives, imports or page declarations.)

For simplicity's sake, assume that all .aspx pages I host are simply .html files renamed with a .aspx extension.

When I point nginx to the location of index.aspx, it asks me to download the file instead of displaying the file's html contents, whereas index.html displays fine.

I have thought of a few ways I could solve this problem.

  • Write an nginx module to process .aspx pages as thought they were html
  • Change recognized mimetypes and associate them with html
    • I tried adding application/aspx html htm shtml; to my nginx mimetype file and it didn't work.
  • Calling cgi to read the .aspx file and generate html which gets returned

My reason for asking this question is because I want to utilize an existing aspx-based web application. This aspx app doesn't have any c# specific code in the aspx files themselves, so it would greatly reduce my work.

NuclearPeon
  • 5,743
  • 4
  • 44
  • 52
  • It sounds like you're trying to do some sort of horrible mutant hybrid of technologies. Want to use Python in a .NET environment? Use [IronPython](http://ironpython.net/). Want to host ASP.NET in a non-IIS server? Use Apache with [mod_mono](http://www.mono-project.com/Mod_mono). – mason Jun 30 '14 at 23:42
  • Hardly. I want files with the extension of .aspx to pass through nginx as though they were .html. I want to use Python on a linux environment that shares code with the .net on windows environment so I don't have to re-write the entire web portion of code. – NuclearPeon Jul 01 '14 at 01:28
  • Why don't you simply strip out all ASP.NET related code and then change the extension to .html if you don't expect the Web Forms pages to be parsed by the ASP.NET engine? – mason Jul 01 '14 at 02:37
  • I would, but the aspx files still utilize the C# code behind mechanisms -- they are placed into SSI scripts, so IIS can still run the code. I want to basically drop the entire web codebase (sans SSI scripts) onto a linux platform and have it display the html exactly as it does on the IIS server. Once I write SSI scripts for the Linux platform, it should have the same functionality using one web codebase. Moving the code behind into .NET CGI scripts is the only other option, and that's much slower/complicated. – NuclearPeon Jul 01 '14 at 05:38

2 Answers2

0

You likely need to use fastcgi. I did something similar for php files so the below examples will likely take some tweaking.

In you nginx configuration file you need something like:

location / {
    root /var/www/yourapp
    index index.html index.htm default.aspx Default.aspx;
    fastcgi_index Default.aspx;
    fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
    include /etc/nginx/fastcgi_params;
}

First you'll notice I have a socket file setup -- php-fmp.sock, so if you don't have that you could do something like 127.0.0.1:9000. Also, if you don't have a fastcgi_params file yet, mine contains:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

Restart Nginx and see what happens and if you get problems, read the error and warning logs. Hopefully, this will get you started.

blh83
  • 495
  • 5
  • 17
  • I'm not using fastcgi, but uwsgi using cgi. I'll update the question with my nginx.conf – NuclearPeon Jul 01 '14 at 01:32
  • I am also using uwsgi on my server. Putting the fastcgi in there is not related to uwsgi so the above can still work. – blh83 Jul 01 '14 at 01:37
  • If I can help it, I'd rather not change the technology I'm using. I would rather look into cgi for IIS so I can keep the web application as standard as possible, ie: without relying on frameworks that only function on one OS or rely on one language. – NuclearPeon Jul 01 '14 at 02:08
0

This isn't the best solution, but I am developing a cgi application that will translate the REQUEST_URI for aspx pages into an open(file).read() and output the aspx page contents to the browser.

I am developing an SSI parser to handle ssi calls, which so far is working for me but a little messy as it works for my setup only right now and has to redirect requests to SSI to my codebase instead of the .NET codebase based on file extension which is a poor solution.

Ultimately, creating an nginx module to handle aspx as it would html and offload ssi to the nginx module would be the best solution methinks.

Thanks to everyone who gave input, I know this question is definitely out in left field. Cheers.

NuclearPeon
  • 5,743
  • 4
  • 44
  • 52