Synology Port forwardding according to subdomain - nginx

In my router setting, I have set as following:
port 5000 - my synology disk station entry
port 1337 - my router panel
And I have set some subdomain to my external IP using DDNS:
wifi.example.com
disk.example.com
www.example.com
What I want to do is:
wifi.example.com redirect to port 1337 and go into router panel
disk.example.com redirect to port 5000 and go into synology panel
www.example.com go to synology web station server
I have tried set port 80 to my disk station in router setting, and want to do redirection in disk station via nginx or reverse proxy which provided by synology. However, I cannot find the nginx.conf in the synology. I tried set the reverse proxy but fail.
Can anyone provide me any clues for this? Appreciate for any help.

I think it must be possible...
unfortunateley it is not possible to specify a port with a DNS entry
but I think the setup you wish must be possible with nginx
the nginx configuration on the Synology is somewhat different
so when you setup wifi.example.com to your home ip-address
then you have to configure your router to port-foward port 80 to port 80 on your synology
on your synology you need to configure the www-station, so the nginx is really the backend. In my case it was first set to Apache
in the www-station you have to create a virtual host entry
after that you have to open a ssh session to your synology
and do a: cd /var/packages/WebStation/etc
the Nginx configuration is in the VirtualHost.json file
in this case you should see something like below:
"eeb4adef-1fc5-4fd5-bacc-1fbd1e747d1c" : {
"backend" : 0,
"fqdn" : "wifi.example.com",
"https" : {
"compatibility" : 1,
"compression" : false,
"hsts" : false,
"http2" : false,
"redirect" : false
},
"index" : [ "index.html", "index.htm", "index.cgi", "index.php", "index.php5" ],
"php" : 4,
"port" : {
"http" : [ 80 ],
"https" : [ 443 ]
},
"root" : "/volume1/web/wiki"
},
"version" : 2
}
now you can remove the "root" line and replace it with:
"return" : "301 http://someurl:1337$request_uri"
After this modification you will have to restart the WebStation service. And when you look with the Virtual Host in WebStation via DSM it will be now presented as AbNormal, but the redirect will (in my case) be working.
I hope this input is usefull for your question.

You can also try my solution:
redirect-http-to-https
Set up a docker container for redirect.
Then you can forword 80(with subdomain) to the docker port and forword 443 to the application port
This will not change any default setting which will avoid the potential problem.

Related

Raspbian / Mercure - bind: permission denied

I'm trying to run Mercure on my Raspbian.
First :
I tried with mercure-legacy_0.13.0_Linux_armv6.tar.gz using the following command to run mercure
JWT_KEY='example'; ADDR='localhost:3000'; DEMO='1'; ALLOW_ANO NYMOUS='1'; CORS_ALLOWED_ORIGINS='*'; PUBLISH_ALLOWED_ORIGINS='*'; PUBLISHER_JWT_KEY='example' ./mercure run
It returns :
"msg":"Unexpected error","error":"listen tcp :80: bind: permission denied"
Second : I tried with mercure_0.13.0_Linux_armv6.tar.gz using the following command to run Mercure
MERCURE_PUBLISHER_JWT_KEY='!ChangeMe!' MERCURE_SUBSCRIBER_JWT _KEY='!ChangeMe!' ./mercure run
Caddy file :
{
{$GLOBAL_OPTIONS}
}
{
auto_https off
}
{$SERVER_NAME:localhost}
log
route {
encode zstd gzip
mercure {
# Transport to use (default to Bolt)
transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db}
# Publisher JWT key
publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
# Subscriber JWT key
subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
# Extra directives
{$MERCURE_EXTRA_DIRECTIVES}
}
respond /healthz 200
respond "Not Found" 404
}
It returns :
run: loading initial config: loading new config: http app module: start: tcp: listening on :443: listen tcp :443: bind: permission denied
Can anyone provide a solution : I intend to host my symfony project on a web server using apache2 on the same Raspberrry
I don't know this specific application, but your error message:
listen tcp :80: bind: permission denied
could be related with restriction for ports 80 and 443 (second message) - non-root user cannot use ports lower than 1024 on standard Linux configuration. Try to use different port or (if you don't care about security - i.e. local hobby project) run app as root.
Keep in mind that you can run Nginx as reverse proxy, so you can run your app on any high port (like 3000) on standard user.
it's a rights issue with your user.
Try with sudo, it should work.

Lighttpd : proxy on another local website

I'm currently stuck on a proxy problem : I use lighttpd to serve html pages on port 443, and now I want to access another local website (only accessible with localhost) and with https, while he can't handle it.
My solution's to use lighttpd as proxy to redirect all requests of the interface 192.168.x.x: in the local interface (127.0.0.1:).
As example, if my local server's on port 8080, all the 192.168.x.x:8080 are redirect on 127.0.0.1:8080, but the url in my browser still 192.168.x.x:8080. With this configuration, i can let lighttpd setup https.
But now I'm stuck on the redirection, i use mod_proxy but nothing work and the page can't be found :
$SERVER["socket"] == "192.168.x.x:8080" {
ssl.engine = "enable"
ssl.pemfile = "/etc/ssl/server.pem"
proxy.server = ( "" => (
"api:8080" => # name
( "host" => "127.0.0.1", # Set the IP address of servername
"port" => 8080
)
)
)
}
what did a do wrong ?
Thanks in advance !
PS : I use the version 1.4.53 of lighttpd
EDIT
To be more precise, I just want a basic proxy usage from ligttpd :
I add ssl engine and ssl pemfile for my 8080 port listener

How to manage many URLs / domains

I would like to get following situation:
I have domains: xxx.com zzz.com and yyy.com
I have one server: xxx.yyy.zz.qq
I would like to configure glassfish to start listening on port 80, and basing on the URL choose proper base catalog for my sites i.e.:
Scenario 1: Visitor is entering url xxx.com or www.xxx.com -> Glassfish receive request on port 80 and pick up catalog: ./glassfish4/myXXXcom/ where index.html for xxx.com is placed.
Scenario 2: Visitor is entering url zzz.com or www.zzz.com -> Glassfish receive request on port 80 and pick up catalog: ./glassfish4/anotherSite/ where index.html for zzz.com is placed.
What have I done:
Installed glassfish 4.1 on my server.
Changed A field of my domains to my server address.
Created virtual server:
glassfish4/bin/asadmin/create-virtual-server --hosts xxx.com xxx
Created http listener:
glassfish4/bin/asadmin create-http-listener --listeneraddress xxx.com --listenerport 80 --default-virtual-server xxx xxx
I think that I am doing something completely wrong here. How do I fix this problem?
If I understand correctly, what you need to do is, create two domains in glassfish or create a cluster and assign two instances of local glassfish instances. One running in port 28080 and another domain in 28081 and use nginx as the load balancer to forward the request to appropriate ports when requests comes from different domains. To make it clear, I am writing step by step
Create a new cluster in glassfish admin console
Create and assign a new local glassfish instance to cluster. This instance will be running in port 28080 and handles requests coming from example1.com
Create another glassfish domain 28081 as the port no for handling example2.com
Install nginx, this acts as proxy and forward request to appropriate
domains. Nginx will be running in port 80.
Start the cluster
Configure nginx as below. This is the crucial part
server {
listen 80;
server_name example1.com;
location / {
proxy_pass http://127.0.0.1:28080;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_pass http://127.0.0.1:28081;
}
}
Start nginx
I hope you are familiar with creating clusters and domains in glassfish. If you are unfamiliar with creating clusters in commandline. Glassfish admin console is there, where you can achieve everything. If you need more info, please feel free to write in comments.

After deploying my rails 3 app on ec2, it doesnt render my app

I am using capistrano, nginx and passenger to deploy my rails 3 app from github on ec2.
This is my deploy.rb file:
set :application, "my-Blog"
set :repository, "https://github.com/whatever/my-Blog.git"
set :scm, :git
role :app, "ec2 DNS"
role :web, "eec2 DNS"
role :db, "ec2 DNS", :primary => true
set :user, 'ec2-user'
set :deploy_to, "/home/ec2-user/apps/Blog"
set :use_sudo, false
default_run_options[:pty] = true
set :deploy_via, :remote_cache
ssh_options[:keys] = ["#{ENV['HOME']}/.ssh/my-key.pem"]
set :keep_releases, 3
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
end
end
And when I run the deploy command, everything is fine and my app is on my ec2 under current directory, which means that the capistrano could get my source code from my github.
On my ec2 instance, I have everything set up: ruby, rvm, mysql, rails, nginx, passenger.
But when I go to my ec2 DNS, it doesnt show my app!
Do you have any suggestion what can be wrong? This is my first deploy though!
Thanks for your answer! I expect to see my application! In aws console, I have: 22 (SSH) and 80 (HTTP), which I guess means that port 80 is open. I think there should be something wrong with my nginx configuration file, this is what I have in this file:
user nginx;
server {
listen 80;
server_name ec2-54-242-228-182.compute-1.amazonaws.com;
# root /home/ec2-user/apps/Blog/current/public;
# passenger_enabled on;
}
}
when I comment the root directory, then on the public DNS url it says "Welcome to nginx on the Amazon Linux AMI! You should now put your content in a location of your choice and edit the root configuration directive in the nginx configuration file /etc/nginx/nginx.conf."
and when I uncomment the root directory then gives me 403 error!
The log file says "current/public/index.html" is forbidden (13: Permission denied)"
The answer depends on what you mean by not showing up. If you're getting a default web page, then your webserver might be trying to resolve a name-based virtual host. In that case, try adding the public IP address of your EC2 instance to your local hosts file.
123.456.789.012 domain-nginx-expects.com
If you are getting no response at all from the server, check the processlist and make sure nginx and passenger are running. Also check your EC2 security group for that instance to make sure that port 80 is open. You can also try telnetting to port 80 while logged into your server:
$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /
Check the port that is in your nginx config whether it's open on your AWS panel.
Check that you can connect to the port using telnet
Check whether you have nginx, passenger running on the server
$ ps -el | grep nginx
Check the nginx access and error logs whether you can see your own activity trying to hit the service.

What is the best way to set ports in PM2?

I'm unsure of the best way to set ports in PM2. I don't see this documented anywhere. I'm using a front-facing nginx server which listens on proxys to specific ports on the backend that represent the node servers. How do I best set this type of configuration up?
One method is with env in process.json
{
"name" : "MyApp",
"script" : "./MyApp/app.js",
"instances" : "1",
"exec_mode" : "cluster_mode",
"env": {"PORT": 3030}
}

Resources