0

I have an instance of nginx running on ports 80 and 443, and I would like to use openvpn with the port 443 in sharing.

So in my server.conf I have this

port 443
port-share 127.0.0.1 4433

proto tcp
;proto udp

And in my nginx.conf

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    client_max_body_size 2M;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    # OpenVPN
    server {
        listen 4433;
    }
}

But when I start nginx daemon first, the openvpn service can't boot with the error :

Mon Jan 18 13:36:19 2016 us=761548 TCP/UDP: Socket bind failed on local address [undef]: Address already in use

And if I start openvpn first, nginx returns :

[emerg] 5301#0: bind() to 0.0.0.0:443 failed (98: Address already in use)

I don't understand why the port-share feature doesn't work.

2
  • I tried : listen {my_public_ip}:4433 but I got same error : TCP/UDP: Socket bind failed on local address [undef]: Address already in use
    – LnlB
    Commented Jan 18, 2016 at 15:17
  • On of your included nginx's files contains listen 443.
    – Alexey Ten
    Commented Jan 19, 2016 at 7:29

2 Answers 2

1

There has to be some .conf file in /etc/nginx/conf.d/, binding on port 443. This leads to the cannot bind error (only one application can bind to a port at a time, at least per listening address).

You write, that you have "nginx running on ports 80 and 443" - I suppose you defined this in the conf.d folder. Simply change the listen directive from 443 to 4433 and it should work.

0

You didn't read the documentation properly. Two daemons cannot share one bind.

In your nginx configuration you should define the following:

listen 127.0.0.1:4433 ssl;

Although my advice - avoid OpenVPN and especially avoid port-sharing in OpenVPN. Using port-sharing is making a parasite connection with the reliability of your web-server and your OpenVPN service. Furthermore, you are relying on the people who are not experienced enough in web-servers and HTTP, and this will lead to even more issues.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .