0

Preciso configurar dois servidores nginx em um servidor windows.

Um deles é responsável pelo processamento do site, e já esta operando usando as configurações padrão do nginx, o que preciso, é de outro nginx, responsável pelo streaming de mídia/videos, como eu poderia configurar-los para funcionar na mesma maquina, como ficaria a configuração?

Eu preciso de dois servidores nginx para isso ou apenas um? Daria para fazer isso com dois?... Separando as operações, caso o servidor de mídia precisasse ser desligado, e o WebServer não por exemplo?

Qual a vantagem de ter o WebServer e o servidor de mídia em um único nginx?

Configuração do WebServer nginx com apache e 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;
        }
    }
}

O que eu poderia fazer para conseguir que servidor de stream nginx funcionasse na mesma maquina com esse WebServer?

2

2 Respostas 2

3

Basta adicionar duas diretivas server. O nginx saberá diferenciar pelo domínio quem deve processar a requisição. Um exemplo de configuração seria:

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

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

Você pode testar no seu computador, sem precisar usar um DNS público, editando o arquivo hosts (Windows: C:\Windows\drivers\etc\hosts, Linux: /etc/hosts) para redirecionar os domínios site.com e media.site.com para o endereço loopback 127.0.0.1.

Não há vantagem em ter duas instâncias independentes do nginx no mesmo servidor, já que servir múltiplos domínios é algo muito convencional e, portanto, uma funcionalidade básica dos servidores HTTP.

É muito comum gerenciar essa situação usando duas pastas, sites-available e outra sites-enabled (é essa a configuração padrão em muitas distros linux). No nginx.conf, não definimos a diretiva server nenhuma vez, e ao invés disso:

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

Para cada site que você precisar servir, você cria um arquivo de configuração em sites-available, esses sim com as diretivas server. Para colocar no ar, basta criar um atalho em sites-enabled e dar reload no nginx. De maneira similar, quando quiser tirar do ar basta deletar o link em sites-enabled e dar reload novamente.

-2

Before starting, make sure LEMP stack is installed on your VPS. You can check the Nginx server status with the following command:

systemctl status nginx Best method to host multiple websites is to create a separate document root directory and configuration file for each website. So, you will need to create a directory structure for both websites inside Nginx web root:

To do so, run the following command for each website:

mkdir /var/www/html/web1.webdock.io mkdir /var/www/html/web2.webdock.io Next, you will need to create sample website content for each website:

First, create a index.html file for web1.webdock.io website:

nano /var/www/html/web1.webdock.io/index.html Add the following html markup which will be served when you connect to the site:

web1.webdock.io

Welcome to the web1.webdock.io with Nginx webserver.

Save and close the file.

Next, create a index.html file for web2.webdock.io website:

nano /var/www/html/web2.webdock.io/index.html Add the following html markup which will be served when you connect to the site:

web2.webdock.io

Welcome to the web2.webdock.io with Nginx webserver.

Save and close the file. Then, change the ownership of both website directories to www-data:

chown -R www-data:www-data /var/www/html/web1.webdock.io chown -R www-data:www-data /var/www/html/web2.webdock.io Create Virtual Configuration Next, you will need to create a virtual host configuration file for each website that indicate how the Nginx web server will respond to various domain requests.

First, create a virtual host configuration file for the web1.webdock.io website:

nano /etc/nginx/sites-available/web1.webdock.io.conf Add the following lines:

server { listen 80; listen [::]:80; root /var/www/html/web1.webdock.io; index index.html index.htm; server_name web1.webdock.io;

location / { try_files $uri $uri/ =404; }

}

Save and close the file. Then, create a virtual host configuration file for the web2.webdock.io website:

nano /etc/nginx/sites-available/web2.webdock.io.conf Add the following lines:

server { listen 80; listen [::]:80; root /var/www/html/web2.webdock.io; index index.html index.htm; server_name web2.webdock.io;

location / { try_files $uri $uri/ =404; }

} Save and close the file. Then, enable each virtual host with the following command:

ln -s /etc/nginx/sites-available/web1.webdock.io.conf /etc/nginx/sites-enabled/ ln -s /etc/nginx/sites-available/web2.webdock.io.conf /etc/nginx/sites-enabled/ Next, check Nginx for any syntax error with the following command:

nginx -t If everything goes fine, you should get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful Finally, restart the Nginx service to apply the configuration changes:

systemctl restart nginx Test Your Websites Now, open your web browser and type the URL http://web1.webdock.io and http://web2.webdock.io. You should see both websites with the content we have created earlier:

web1.webdock.io

Fonte : https://webdock.io/en/docs/how-guides/shared-hosting-multiple-websites/how-configure-nginx-to-serve-multiple-websites-single-vps

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .