Here's my situation:
I have a linux server from Scaleway hosting a SHOUTcast service, on the ip 1.2.3.4, port 8000
Recently I also rented a domain myserv.com so I can redirect the server to.
I changed the Nameserver to the ones provided by https://dns.he.net and started making records.
Got an A record to point my domain to the IP address, and it's working fine.
I can access my server by opening myserv.com:8000, but I'd like to access the SHOUTcast service with a subdomain, rather than adding the port. Let's say if I open sc.myserv.com it'll access 1.2.3.4:8000
I did some search and fount out I'd need to use SRV records, but I guess I didn't configure mine right cause it's not working. What am I doing wrong?
myserv.com. 86400 IN A 1.2.3.4
_shoutcast._tcp.sc.myserv.com. 86400 IN SRV 0 5 8000 myserv.com.
Thank you in advance
No idea about Apache, but if you are running Nginx then this is really straightforward.
It's just a case of setting a proxy directive in your server configuration to route all requests to your subdomain to the Shoutcast server on your machine. Something along these lines:
server {
server_name sc.myserv.com www.sc.myserv.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8000;
proxy_read_timeout 90;
proxy_redirect off;
proxy_buffering off;
tcp_nodelay on;
}
}
If your Shoutcast stats show your server IP address instead of the listeners IP then inside the server block but outside of the location block try adding:
set_real_ip_from <YOUR_SERVER_IP>;
real_ip_header X-Real-IP;
real_ip_recursive on;
You can also match requests using regex, which in turn makes the captured matches available as variables. So your location directive becomes:
location ~ /(.*) {
This will now capture anything you add to your proxied url. Then to pass the captured path along your proxy_pass becomes:
proxy_pass http://127.0.0.1:8000/$1;
or for some awkward clients you might want to specify it's an mp3 in the url, like this:
proxy_pass http://127.0.0.1:8000/$1/stream.mp3;
You can't use SRV records for this. There isn't client support.
If you want to access your SHOUTcast/Icecast/HTTP/HTTP-like service on its default port of 80, you need to use port 80, not 8000.
Related
I have two Docker instances running Wordpress and my Nodejs application separately in the same machine.
Now I want to set up Nginx to accept connections only on my domain (mydomain.com). So if users access to mydomain.com/ they should be redirected to wordpress container, and if they access to mydomain.com/customer, the request should be redirected to Nodejs app container.
This schema explains the idea:
I am not very good at Nginx and it is being so difficult for me to edit the config. file to match that schema. Also I dont find any kind of examples or documentation to achieve this configuration. Is it so weird?
It is the very common nginx usage example. The very basic setup you need is
server {
listen 80;
server_name mydomain.com;
proxy_set-header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://<docker1_address:port>;
}
location /customer {
proxy_pass http://<docker2_address:port>;
}
}
server {
# this would be the default server for all requests
# where HTTP Host header is missing or not equal to 'mydomain.com'
listen 80 default_server;
# close the connection immediately
return 444;
}
I'm a little new to VPS/Linux so please bear with me.
I have a domain name (attendahh.com) pointed to my host's nameservers.
I've set up /etc/nginx/conf.d/attendahh.com.conf as follows:
# the IP(s) on which your node server is running. I chose port 3000.
upstream attendahh.com {
server 127.0.0.1:1999;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name attendahh.com attendahh;
access_log /var/log/nginx/attendahh.log;
# pass the request to the node.js server with the correct headers and much $
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://attendahh.com/;
proxy_redirect off;
}
}
Then I service nginx restart.
I've read a bunch of tutorials and stack answers this is ostensibly all I need to do, but if I go to http://attendahh.com it does not work.
Things to note:
Going to my IP + port in the browser works just fine ( 23.226.227.16:1999 )
I have Cpanel for VPS installed (I tried to set up the DNS in there originally but it didn't work, I've since deleted the dns entry from there but it may still be affecting things)
Apache virtual hosts are commented out in httpd.config.
Any ideas on what I'm doing wrong here? Perhaps there's some conflict between apache and nginx?
- proxy_pass http://attendahh.com/;
+ proxy_pass http://attendahh.com;
Nginx uses its own resolver, it doesn't use the system's resolver (/etc/resolver).
You have to configure it using the resolver directive. If you are not using the resolver directive, then use IP address in the proxy_pass directive.
Source: http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver
I have nginx in front which give proxy pass to node server.
How do I get the domain name which nginx pass to node.
I tried req.headers.host which gives IP address instead of domain name.
e.g. if current url is "http://xyz.abc.com/" then I want http://xyz.abc.com/ but I get ip like 127.0.0.1
How do I get domain name??
You can pass the correct host header from nginx to your Node.js app via the $host variable. You'll need something like this in your nginx.conf file under the server/location section:
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:3002$request_uri;
proxy_redirect off;
break;
}
I am new to nginx and I'm struggling to get my configuration for a reverse proxy working. I have a node app running on localhost:3010 and I'm trying to serve pages through nginx from this app at the subdomain dev.[sitename].org. Let's just say dev.example.org for readability. Here are the contents of a file I created in sites-available called example.org (is that the correct name for this file?):
server {
server_name www.example.org example.org;
}
upstream app_dev.example.org {
server 127.0.0.1:3010;
}
server {
listen 0.0.0.0:80;
server_name dev.example.org;
access_log /var/log/nginx/dev.example.access.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_dev.example.org/;
proxy_redirect off;
}
}
This is mostly based off this related question: Node.js + Nginx - What now? however when I try to open dev.example.org in my browser, Chrome reports that it can't find the page. I can ping dev.example.org and get an IP address, so the server seems to be available, but my nginx configuration incorrect. I created the symlink in sites-enabled and restarted nginx, in case you thought I might have forgotten those steps.
So my thought now is that I'm not referring to the subdomain correctly somewhere, or maybe my file in sites-available is named wrong. Any push in the right direction would be appreciated.
Just to be sure the problem is on nginx try these steps:
Set a test server at port 3030, serving the system doc folder or anything else.
server {
listen 3030
location / {
root /usr/share/doc/;
autoindex on;
}
}
upstream simple_test {
server 127.0.0.1:3030
}
Then use simple_test below as well:
proxy_pass http://simple_test/;
If you see the /usr/share/doc dir listing when you access dev.example.org then your issue is on the node side.
Turned out something was blocking port 80! fixed that and the config as posted above worked
I have a few applications that are running localy in defferents ports, how can I configure NGINX server for forwarding request from port 80 to my application depends on income domain name. For example 2 local apps named 'app1' on port 8181 , and if request comes from http://app1.com - nginx forwards to http://localhost:8181
I've looked at nginx docs, I ask for your examples if someone did this.
Thanks
Assuming you want to create a reverse proxy, my method is to first configure the following reverse proxy settings in a new file called /etc/nginx/reverse-proxy.conf:
# Serve / from local http server.
# Just add the following to individual vhost configs:
# proxy_pass http://localhost:3001/;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
Then, for each reverse proxy I'm configuring, I add an appropriately-named configuration file in /etc/nginx/sites-enabled with the following:
server {
server_name app1.com;
server_name www.app1.com;
location / {
include /etc/nginx/reverse-proxy.conf;
proxy_pass http://localhost:8181/;
}
}
You can create as many server blocks as you like and point them at different local (or even remote) application servers. You can also add location blocks to serve different URLs within the same domain statically, or from different local application servers.
(You can also just roll all the configuration into /etc/nginx/nginx.conf, but I find it easier to separate configuration out into multiple files.)
I managed to do this easily by following this tutorial.
Create a new file in /etc/nginx/conf.d/ called your-domain.com.conf and put this in it:
server {
listen 80;
server_name your-domain.conf.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
Then restart nginx
sudo service nginx restart