Proxy .cfm to a CF server - nginx

I'd like to use Nginx as a proxy server for ColdFusion.
I'm forced to use ColdFusion 9. CF Developer Edition is installed using multiserver. The inbuit jrun server is running on port 8300 and I can access the admin panel at http://localhost:8300/CFIDE/administrator/index.cfm as described in the installer.
I have a hosts entry:
127.0.0.1 example.com
and the nginx config file is the following:
server {
listen 80;
server_name example.com;
root /home/user/dev/cf;
index index.cfm;
location ~ \.cfm$ {
proxy_pass http://127.0.0.1:8300;
}
}
There is a file /home/user/dev/cf/index.cfm with the following content:
<cfoutput>
<h1>Dupa</h1>
</cfoutput>
However, when I access http://example.com or http://example.com/index.cfm, I get a 404 error. The docroot also contains static files which are served normally, e.g. http://example.com/sitemap.xml.
Am I missing something? What should I do to proxy cfm files to the cf server?

Related

Basic proxy_pass from nginx from one local ip to another local ip

I am a new user of nginx and I am following a video guide from Linode on youtube (How to Set Up an NGINX Reverse Proxy).
I have a working nginx and apache server both on port 80. I know that because when I type the ip address of both in firefox, it directs me to nginx/apache welcome page.
The youtube video configuration template is as follow (where the server_name is the linode ip) :
server {
listen 80;
listen [..]:80;
server_name 172.105.104.226;
location / {
proxy_pass http://localhost:3000/;
}
On my Proxmox machine, the nginx server is on a VM at 192.168.1.241 and the apache server on another VM at 192.168.1.243.
Looking at nginx documentation we find that this :
location /some/path/ {
proxy_pass http://www.example.com/link/;
}
should proxy all the traffic received on the nginx listening port and redirect it to the address specified by proxy pass.
With all these information, my configuration file is like this :
server {
listen 80;
listen [::]:80;
server_name 192.168.1.241;
location / {
proxy_pass http://192.168.1.243;
}
}
My understanding is that this configuration file should listen at the address 192.168.1.241 on port 80 (nginx server) and redirect it to the specified address 192.168.1.243 (apache server)/
If i understand correctly, Location / should take the request as is received on the nginx server and redirect it to the apache server.
However, when I enter 192.168.1.241 in my browser, it doesn't show the apache welcome message but shows the nginx welcome message. That means that the proxy isn't working.
My nginx understanding is extremely limited as I am just starting to learn, but to me it seems like this should work but doesn't.
Thank you for your help
It turns out that the configuration is correct.
The problem was that the webpage was cached. By forcing a full refresh, 192.168.1.241 redirected to 192.168.1.243 successfully.

nginx proxy_pass serving from default path other than application's

I'm running a local web service listening on port 8888
server {
listen 80;
server_name dracut.site;
location /jupyter {
proxy_pass http://127.0.0.1:8888/;
}
}
When I access http://dracut.site/jupyter, nginx is using files under /etc/nginx and returns error.
"/etc/nginx/html/tree" failed (2: No such file or directory)
Files should be served from the app listening on port 8888, how can I configure it.
your desciption is not complete...
you're using static html?
then want nginx to serve it...
just define root then location tag to that root

Configuring nginx to direct to website in server

I have a remote centOS server running locally on 127.0.0:8000 which I want to proxy with nginx.
I have tested that the server runs on that address and that nginx passes the tests.
When i try to access the ip on my browser I get:
I understand I need to edit the configuration files for nginx. I just don't know how.
I tried going to /etc/nginx/conf.d/index.conf (I named my app index because, reasons)
And I write the following:
server {
listen 80;
server_name www.<address>.com;
location / {
proxy_pass http://127.0.0.1:8000;
root /home/<user>/WebApp/templates;
index index.html;
}
}
And index.html is on the path I put on root. What am i doing wrong?

Nginx Subdomain accessible on subdomain its not configured for

I have my staging config setup like so:
server {
listen 80;
server_name staging.domain.com;
root /var/www/staging/public;
and my production config setup like this:
server {
listen 80;
server_name www.domain.com;
root /var/www/production/public;
With no other redirects or anything.
The issue is that even if I disable the production config I can still access the staging server at www.domain.com.
Why is it not being restricted to its configured subdomain?
I've answered a similar question like this before
Let me start with a small explanation on how nginx matches the hosts, quoting from how nginx processes a request
In this configuration nginx tests only the request’s header field
“Host” to determine which server the request should be routed to. If
its value does not match any server name, or the request does not
contain this header field at all, then nginx will route the request to
the default server for this port.
When you disable the main server you only have 1 left, so nginx passes the request to it, if you want to avoid that you need to add a main server to block all unconfigured domains
server {
listen 80 default_server;
return 403;
}
Then run
sudo service nginx reload
Then you're set

How to test nginx subdomains on localhost

I want to test nginx subdomains before uploading config to the server. Can i test it on localhost? I try
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
}
}
server {
listen 80;
server_name sub.localhost;
location / {
proxy_pass http://localhost:8080/sub;
}
}
And it does not work. Shoulld i change my hosts file in order to make it work? Also, after uploading site to the server should i change DNS records and add sub.mydomain.com?
Yes, add '127.0.0.1 sub.localhost' to your hosts file. That sub has to be resolved somehow. That should work.
Then once you're ready to go to the net, yes, add an a or cname record for the subdomain sub.
When I use proxy_pass I also include the proxy.conf from nginx.
http://wiki.nginx.org/HttpProxyModule
In Linux based OS just to edit as sudo /etc/hosts file and change 127.0.0.1 localhost to 127.0.0.1 *.localhost.
So at /etc/nginx/sites-enabled/<environment>/<your_project_name> edit server_name key as <subdomain>.localhost.
Reload nginx and networking service.
$ sudo service nginx reload
$ sudo service networking reload
And then try http://<subdomain>.localhost at url bar.
It works for me.
UPDATE
In my opinion, a better solution is creating a virtual server that only responds if subdomain doesn’t exist, at /etc/nginx/sites-enabled/development/default, as default server (remember that you can define only one server as default).
server {
listen 80 default_server;
root /var/www/html/errors/404;
server_name *.localhost *.<host-name>;
location / {
index subdomain.html;
}
}
Make sure that in nginx.conf (generally at /etc/nginx/nginx.conf) contain include /etc/nginx/sites-enabled/**/*; to this virtual server work. If not, put it and then run $ sudo service nginx reload.
In this case isn't necessary put *.localhost in /etc/hosts, but only localhost.
For your public webserver with its own domain name, you just need to add a Canonical name using a CNAME record in your DNS configuration:
CNAME * example.com.
Once this is done, set your nginx setting
server_name *.example.com example.com;
In your local setup you can keep the same configuration for nginx but unless you have a local DNS setup, you will have to edit your /etc/hosts file and add each subdomain manually. wildcards don't work in the /etc/hosts file.
127.0.0.1 abc.example.com def.example.com ghi.example.com
It is generally recommended to use .local as the namespace for your local domains.
With an Nginx configuration like shown by the OP, all that is needed is to configure the local DNS resolution. I run Linux containers on a VM with a local DHCP IP but test them on Windows 10 browsers.
The DNS configuration can be done by editing "C:\Windows\System32\drivers\etc\hosts" as Administrator.
192.168.100.50 sub.example.local
192.168.100.50 example.local
Of course, use 127.0.0.1 or other appropriate IP as needed.

Resources