title: Nginx virtual host not working (wrong redirect)
body: <p>i'm new to nginx and i have a problem with virtual host. The virtual host didn't work when i try to access the vhost it'll be redirect to localhost "Welcome to nginx". Here are the contents of my config:</p>
  
  <p><strong>/etc/hosts</strong> config:</p>
  
  <pre><code>127.0.0.1 localhost localhost.localdomain
  
  ::1 localhost localhost.localdomain
  
  ****Generated by Admin****
  
  18.200.10.50 mail.testingweb.com
  
  18.200.10.50 testingweb.com
  </code></pre>
  
  <p>SSL config on <strong>/etc/nginx/conf.d/ssl.conf:</strong></p>
  
  <pre><code>server {
         listen 443 default_server ssl;
         server_name testingweb.com;
  
         ssl_certificate /etc/nginx/sslcert/xxxx.crt;
         ssl_certificate_key /etc/nginx/sslcert/xxxxx.key;
  
         ssl_session_cache shared:SSL:10m;
         ssl_session_timeout 10m;
         keepalive_timeout 70;
  
         ssl_prefer_server_ciphers on;
         ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNU$
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  
         location / {
                 root /usr/share/nginx/html;
                 index index.php index.html index.htm;
         }
  
          location ~ \.php$ {
                  try_files $uri =404;
  
                  # With php5-fpm:
                  fastcgi_pass unix:/var/run/php5-fpm.sock;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
          }
  
  }
  </code></pre>
  
  <p><strong>/etc/nginx/sites-available/default</strong> config:</p>
  
  <pre><code>server {
          listen 80 default_server;
          # listen [::]:80 default_server ipv6only=on;
  
          root /usr/share/nginx/xhtml;
          index index.php index.html index.htm;
  
  
          # Make site accessible from http://localhost/
          server_name testingweb.com;
          return 301 https://$host$request_uri;
  
          location / {
                  try_files $uri $uri/ =404;
          }
          error_page 404 /404.html;
  
          # redirect server error pages to the static page /50x.html
  
          error_page 500 502 503 504 /50x.html;
          location = /50x.html {
                  root /usr/share/nginx/html;
          }
  
          # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
          #
          location ~ \.php$ {
                  try_files $uri =404;
  
          #       # With php5-fpm:
                  fastcgi_pass unix:/var/run/php5-fpm.sock;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
          }
  
  
          # deny access to .htaccess files, if Apache's document root
          # concurs with nginx's one
          #
          location ~ /\.ht {
                  deny all;
          }
  }
  server {
          listen 80;
          listen 443;
          return 403;
  }
  </code></pre>
  
  <p>I want to access another sites from new root directory, <strong>/usr/share/nginx/html/www</strong> on www directory there is a <strong>wordpress</strong>.</p>
  
  <p><strong>/etc/nginx/sites-available/testingweb</strong> config:</p>
  
  <pre><code>server {
          listen 80 default_server;
          # listen [::]:80 default_server ipv6only=on;
  
          root /usr/share/nginx/html/www;
          index index.php index.html index.htm;
  
  
          # Make site accessible from http://localhost/
          server_name testingweb.com;
  
  #       rewrite ^ https://$http_host$request_uri? permanent;
          return 301 https://$host$request_uri;
  
          location / {
                  # First attempt to serve request as file, then
                  # as directory, then fall back to displaying a 404.
                  try_files $uri $uri/ /index.php?q=$uri&amp;$args;
                  # Uncomment to enable naxsi on this location
                  # include /etc/nginx/naxsi.rules;
          }
  
  
     error_page 404 /404.html;
  
      # redirect server error pages to the static page /50x.html
      #
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
              root /usr/share/nginx/html;
      }
  
          location ~ \.php$ {
                  try_files $uri =404;
  
          #       # With php5-fpm:
                  fastcgi_pass unix:/var/run/php5-fpm.sock;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
          }
  
  #       location = /favicon.ico {
  #               alias /usr/share/nginx/html/favicon.ico;
  #       }
  
  
          # deny access to .htaccess files, if Apache's document root
          # concurs with nginx's one
          #
          location ~ /\.ht {
                  deny all;
          }
  }
  </code></pre>
  
  <p>According the configs, what's wrong with my config ? i cannot access the wordpress file on <strong>/usr/share/nginx/html/www</strong> directory by domain <strong>testingweb.com</strong> ? its always redirect to <strong>default</strong> host instead of <strong>testingweb</strong> host ?</p>
  
  <p>sorry for my bad english..</p>