How to configure multiple Nginx on a server?

1

I need to setup two nginx servers on a windows server.

One of them is responsible for processing the site, and is already operating using the default settings of nginx, what I need, is another nginx, responsible for streaming media / videos, how could I configure them to work in the same machine, what would the configuration look like?

I need two nginx servers for this or just one? Could you do this with two? ... Separating the operations in case the media server needed to be shut down, and the WebServer not for example?

What is the benefit of having the WebServer and the media server in a single nginx?

WebServer configuration nginx with apache and php, nginx.conf :

#user  nobody;
worker_processes  2;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    include       proxy.conf;
    index  index.html index.htm index.php;
    default_type  application/octet-stream;

    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  logs/access.log  main;

    # Hide nginx version information.
    server_tokens off;

    # Update charset_types due to updated mime.types
    charset_types text/xml text/plain text/vnd.wap.wml application/x-javascript application/rss+xml text/css application/javascript application/json;

    root   C:/xampp/htdocs;

    sendfile        on;

    # Tell Nginx not to send out partial frames; this increases throughput
    # since TCP frames are filled up before being sent out. (adds TCP_CORK)
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    # Compression
    # Enable Gzip compressed.
    gzip  on;
    gzip_comp_level   5;
#    gzip_http_version 1.0;
    gzip_min_length   256;
    gzip_proxied      any;
    gzip_vary         on;
    # Compress all output labeled with one of the following MIME-types.
    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rdf+xml
        application/rss+xml
        application/schema+json
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-javascript
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/eot
        font/opentype
        image/bmp
        image/svg+xml
        image/vnd.microsoft.icon
        image/x-icon
        text/cache-manifest
        text/css
        text/javascript
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        text/x-cross-domain-policy
        text/xml;

    server {
        listen       *:80;
        #listen       [::]:80  default ipv6only=on;
        #server_name  localhost;
        #server_name  app.meusite.com;


        charset utf-8;

        #https://github.com/h5bp/server-configs-nginx
        include h5bp/basic.conf;

        location / {
            root   C:/xampp/htdocs;
        }

        location ~ .php$ {
            # essentially the same as passing php requests back to apache

            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8185;
        }

        location ~ .custom$ {
            # essentially the same as passing php requests back to apache

            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8185;
        }

        #Adding location for phpmyadmin
        location /phpmyadmin {
            proxy_pass         http://127.0.0.1:8185/phpmyadmin;
#            allow 127.0.0.1;
#            deny all;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

What could I do to get the nginx stream server running on the same machine with this WebServer?

    
asked by anonymous 10.10.2016 / 23:59

1 answer

1

Just add two server directives. The nginx will know how to differentiate by the domain who should process the request. An example configuration would be:

server {
    listen       80;
    server_name  example.org  www.example.org;
    ...
}

server {
    listen       80;
    server_name  media.example.org;
    ...
}

You can test your computer, without having to use public DNS, by editing the hosts file (Windows: C:\Windows\drivers\etc\hosts , Linux: /etc/hosts ) to redirect the domains site.com and media.site.com to the address loopback 127.0.0.1.

There is no advantage in having two independent instances of nginx on the same server, since serving multiple domains is something very conventional and therefore a basic functionality of HTTP servers.

It is very common to manage this situation using two folders, sites-available and other sites-enabled (this is the default setting for many linux distros). In nginx.conf, we did not set the server directive at any time, and instead:

[...]
http {
    [...]
    include /etc/nginx/sites-enabled/*.conf;
}

For each site you need to serve, you create a configuration file in sites-available , these are yes with server directives. To put in the air, just create a shortcut in sites-enabled and give reload in nginx. Similarly, when you want to get out of the air just delete the link in sites-enabled and reload again.

    
11.10.2016 / 06:07