I'm trying to get the https://domain.ltd redirected to https://www.domain.ltd on Nginx (note the www), here's the config:  server {     listen 80;     server_name domain.ltd;     return 301 https://www.$host$request_uri; } server {     listen 443;     server_name domain.ltd;     return 301 https://www.$host$request_uri; } server {     listen 443 ssl;     server_name www.domain.ltd domain.ltd;     ...main config goes here }   What I found strange is that all other options work fine:  http://domain.ltd redirects to https://www.domain.ltd  http://www.domain.ltd redirects to https://www.domain.ltd  https://www.domain.ltd works too  But no way for https://domain.ltd, it only shows ERR_CONNECTION_REFUSED.  What's the problem with configuration? How do I solve it?  UPD. I have both www.domain.ltd and domain.ltd included in my SSL cert, so there's no reason not to work
121029
I'm using nginx with SSL, and I want to always redirect to www, regardless of whether the request is http or https. I just want to redirect to the respective protocol www version.  I have the port 80 server block working fine. Beneath my first server block I have...  server {     listen      80;     server_name example.com;     return 301  $scheme://www.example.com$request_uri; }   and this works fine. But for my port 443 server block for https, I have all kinds of information inside regarding ssl on and different ciphers to use.  I really don't want to mess up anything up related to security by doing something stupid.. so my question is on this block for port 443...  server {     listen      443;     server_name example.com;     return 301  $scheme://www.example.com$request_uri; }   do I need anything else? do I need ssl on or any other security related things? If they visit non-www does that mean it transfers the request insecurely or something (even for a split second while its redirecting?)  Just want to make sure what I have is solid and secure. It seems to work but I want to double check.  Thanks!
42539
Previously I asked a question here:  about setting up secure and non-secure domains on a single IP.  Opinions were mixed, but it appears SNI hold the solution. Unfortunately I cannot get it work as required.    — Works as expected  — Presents domaina.com certificate, not as expected. I would like it to not respond to SSL requests.   I would like my server to only send the certificate for domaina.com and no other host names, even if this means sending a 403 error to non-SNI clients. My current configuration on vanilla Ubuntu Server 12.04 LTS is below:  Ports.conf  … &lt;IfModule mod_ssl.c&gt;     NameVirtualHost *:443     Listen 443 &lt;/IfModule&gt; …   Domain A Virtual Host  &lt;VirtualHost *:80&gt;     ServerName   domaina.com     ServerAlias  www.domaina.com     DocumentRoot /var/www/domaina.com/public     ErrorLog     /var/www/domaina.com/logs/error.log     CustomLog    /var/www/domaina.com/logs/access.log combined &lt;/VirtualHost&gt;  &lt;IfModule mod_ssl.c&gt; &lt;VirtualHost *:443&gt;     ServerName   domaina.com     ServerAlias  www.domaina.com     DocumentRoot /var/www/domaina.com/public     SSLEngine on     SSLCertificateFile      /etc/apache2/ssl/domaina.com.crt     SSLCertificateKeyFile   /etc/apache2/ssl/domaina.key     SSLCertificateChainFile /etc/apache2/ssl/domaina.com.ca-bundle &lt;/VirtualHost&gt; &lt;/IfModule&gt;   Domain B Virtual Host  &lt;VirtualHost *:80&gt;     ServerName   domainb.com     ServerAlias  www.domainb.com     DocumentRoot /var/www/domainb.com/public     ErrorLog     /var/www/domainb.com/logs/error.log     CustomLog    /var/www/domainb.com/logs/access.log combined &lt;/VirtualHost&gt;   apache2ctl -S  VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:443                  is a NameVirtualHost          default server domaina.com (/etc/apache2/sites-enabled/domaina.com:12)          port 443 namevhost domaina.com (/etc/apache2/sites-enabled/domaina.com:12) *:80                   is a NameVirtualHost          default server domaina.com (/etc/apache2/sites-enabled/domaina.com:3)          port 80 namevhost domaina.com (/etc/apache2/sites-enabled/domaina.com:3)          port 80 namevhost domainb.com (/etc/apache2/sites-enabled/domainb.com:1) Syntax OK   How can you get rid of the defaults?
28940
tl;dr : For SEO, should I redirect from one to the other or list both on the DNS records?    It seems that most experts think that both www and non-www should exist. (Please correct me if I'm wrong.) And Google Webmasters Tools lets you choose which is the main one.  But: will a redirect give all SEO weight to one of them instead of splitting it? (There are other search engines after all, so setting the main one in Google Webmasters Tools might not be enough.) Will having both on the DNS records give them more importance? No difference?
88597
I'm using this .htaccess that pass everything after URL to $param, so example.com/news/id goes to PHP as $_GET['param']='news/id'. But Nginx is always throwing me to 404 page.  My .htaccess:  RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule  (.*) index.php?param=$1    What I tried in Nginx default.conf:   server {         listen 80;         listen [::]:80;     server_name domain.com;         root    /var/www/html;          location / {                 if (!-f $uri){                         set $rule_0 1$rule_0;                 }                 if (!-d $uri){                         set $rule_0 2$rule_0;                 }                 if ($rule_0 = "21"){                 rewrite ^(.*) index.php?param=$1;                 }         } }
123352
I used to operate a website with an SSL certificate, but have stopped using the SSL certificate. The problem is that most of the external links to the website use the https:// prefix.  I have tried the https:// to http:// redirect in the .htaccess file:  RewriteEngine On  RewriteCond %{HTTPS} on RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}   But it seems, as has been pointed out elsewhere, that the server is trying to retrieve the certificate before activating the redirect. Hence, an error is shown before the redirect is ever accomplished. The error is either a warning that the certificate is expired, or if I delete the certificate signing request, then an error that SSL received a record that exceeded the maximum permissible length.  Is there any way to allow the incoming links to be redirected properly?
116725
I've just read  which essentially says that when I set up DNS for example.com, the root record can't be a CNAME, it has to be an A record.  My question is, why?   I'm sure the clever people who designed DNS didn't make arbitary restrictions for no reason, but I don't see what we gain by requring root domains to be A records. I would love to just point my example.com domain to someserver.somewebhost.example and forget about it, but I can't.  Please enlighten me, billpg.
104449
How can I use varnish cache with nginx SSL termination for my SSL-Only (Https only) website? I use ubuntu 18.04 and I am currently running a wordpress site on my server.
108360
I developed my website under /var/www/html (for the development part) so I can consult the website when I enter the server's IP address into my web browser. On the same server I have the same products under /var/www/example.com and it's this domain than I want indexed on Google.  My problem is that Google has indexed both. So sometimes the goods appears in Google with example.com and sometimes Google displays the IP address of the server.  So I added meta robots noindex nofollow, and also disallow: / into robot.txt to remove the IP address version of the site from Google search console.  However, the IP address was still showing up in Google.  So I decided to remove completely all files under /var/www/html and left just the nginx html page. However, I still have the same problem. The IP address is always displayed in Google. I noticed than the meta description is ignored too. Google takes the old description.  Can you tell me if I did something wrong or what I have to do to remove this IP from google search. How long do we need to wait to see changes?
124288
I need a single Wordpress installation to be available from both the main domain (www.example.com) via HTTP and a subdomain (secure.example.com) via HTTPS.  Of course i can just map the subdomain to the Wordpress folder in Nginx config. But will Wordpress be aware that it is called via HTTPS and change all links on the pages to HTTPS ?  Also, how i can i force certain pages to be automatically redirected to their HTTPS equivalent permalink (and then back again to HTTP) ?
590
I would like to redirect www.example.com to example.com. The following htaccess code makes this happen:  RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]   But, is there a way to do this in a generic fashion without hardcoding the domain name?
104292
Is there a way to redirect all my subdomains without specify the domain, I mean for example:  when I write www it should resolve to www.mydomain.com or if I write ftp it should redirect to ftp.mydomain.com  I know I could write wildcards in the hosts file but I'm not sure how to write something where the wildcard take the subdomain and concatenate it with mydomain.com
82659
There appear to be many questions and guides out there that instruct how to setup nginx to redirect http requests to https. Many are outdated, or just flat out wrong.   # MANAGED BY PUPPET  upstream gitlab {   server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; }  # setup server with or without https depending on gitlab::gitlab_ssl variable server {   listen *:80;   server_name gitlab.localdomain;   server_tokens off;   root /nowhere;   rewrite ^ https://$server_name$request_uri permanent; } server {   listen *:443 ssl default_server;   server_name gitlab.localdomain;   server_tokens off;   root /home/git/gitlab/public;    ssl                           on;   ssl_certificate               /etc/ssl/certs/ssl-cert-snakeoil.pem;   ssl_certificate_key           /etc/ssl/private/ssl-cert-snakeoil.key;   ssl_protocols                 SSLv3 TLSv1 TLSv1.1 TLSv1.2;   ssl_ciphers                   AES:HIGH:!ADH:!MDF;   ssl_prefer_server_ciphers     on;    # individual nginx logs for this gitlab vhost   access_log  /var/log/nginx/gitlab_access.log;   error_log   /var/log/nginx/gitlab_error.log;    location / {     # serve static files from defined root folder;.     # @gitlab is a named location for the upstream fallback, see below     try_files $uri $uri/index.html $uri.html @gitlab;   }    # if a file, which is not found in the root folder is requested,   # then the proxy pass the request to the upsteam (gitlab puma)   location @gitlab {     proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694     proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694     proxy_redirect     off;      proxy_set_header   X-Forwarded-Proto $scheme;     proxy_set_header   X-Forwarded-Ssl   on;      proxy_set_header   Host              $http_host;     proxy_set_header   X-Real-IP         $remote_addr;      proxy_pass http://gitlab;   } }   I've restarted after every configuration change, and yet I still only get the 'Welcome to nginx' page when visiting http://192.168.33.10. whereas https://192.168.33.10 works perfectly.   Why will nginx still not redirect http requests to https?   I've also tried the following configurations      listen *:80;   server_name &lt;%= @fqdn %&gt;;   #root /nowhere;    #rewrite ^ https://$server_name$request_uri? permanent;    #rewrite ^ https://$server_name$request_uri permanent;   #return 301 https://$server_name$request_uri;   #return 301 http://$server_name$request_uri;   #return 301 http://192.168.33.10$request_uri;   return 301 http://$host$request_uri;   The logs   tailf /var/log/nginx/access.log 192.168.33.1 - - [22/Oct/2013:03:41:39 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0" 192.168.33.1 - - [22/Oct/2013:03:44:43 +0000] "GET / HTTP/1.1" 200 133 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0"  tailf /var/log/nginx/gitlab_error.lob 2013/10/22 02:29:14 [crit] 27226#0: *1 connect() to unix:/home/git/gitlab/tmp/sockets/gitlab.socket failed (2: No such file or directory) while connecting to upstream, client: 192.168.33.1, server: gitlab.localdomain, request: "GET / HTTP/1.1", upstream: "http://unix:/home/git/gitlab/tmp/sockets/gitlab.socket:/", host: "192.168.33.10"   Resources
80774
How do i redirect a url to domain .  eg.  -->  How do i redirect a non-www to www WITHOUT a slash at end ?   eg  --->
69484
As title says,  I want to set my apache to listen on 443, and will configure SSL.   So, My Question  is :-  1). Does that mean, i will not have port 80 or any other port which is no ssl ? 2). My site can only be accessed via https and no http ? Thanks
101761
I have this configuration :  location / {     root /etc/nginx/euchet; }  location /app/ {     proxy_pass http://172.16.184.2:8080;     proxy_redirect off;     proxy_set_header Host $host;     proxy_set_header X-Real-IP $remote_addr;     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;     proxy_set_header REMOTE_ADDR $remote_addr; }   And I need to add another location with auth_basic enabled only for the request: /app/f?p=3000  I tried with rexexp:     location ~ \/appt\/f\?p=3000 {             auth_basic "Hello! Enter password";             auth_basic_user_file /etc/nginx/euchet.htpasswd;              proxy_pass http://172.16.184.2:8080;             proxy_redirect off;              proxy_set_header Host $host;             proxy_set_header X-Real-IP $remote_addr;             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;             proxy_set_header REMOTE_ADDR $remote_addr;     }   Nginx use previous location /app/.  I tried another way:  location ~* /euchet/f {      if ($arg_p = "4550") {         return 403;     }      error_page 403 = @hidden; }     location @hidden {             auth_basic "Hello! Enter password";             auth_basic_user_file /etc/nginx/euchet.htpasswd;              proxy_pass http://172.16.184.2:8080;             proxy_redirect off;              proxy_set_header Host $host;             proxy_set_header X-Real-IP $remote_addr;             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;             proxy_set_header REMOTE_ADDR $remote_addr; }   And I get 403 error on f?p=3000, and 404 errors on f?p=&lt;another_number&gt;  How can I fix this problem?
66283
My code doesn't work with second level tld's like domain.co.uk Here is my conf:   # add www.   if ($host ~ ^(?!www)) {    rewrite ^/(.*)$ http://www.$host/$1 permanent;   }    # remove subdomain   if ($host ~ &quot;^www\.(.*)\.(.*\.([a-z]{2,4}|[a-z]{2}\.[a-z]{2}))&quot;) {    set $host_without_sub $2;    rewrite ^/(.*)$ http://www.$host_without_sub/$1 permanent;   }
96705
I've recently set up a website with a smaller hosting company. The plan has a dedicated IP.  They sent me emails to say it's all set up, but now their support channels are all unresponsive even though they say it's open 24 hours.  In the File Manager in the cpanel I've put an index.html file in the public_html directory. But when I point my browser to the IP address given to me, it comes up with the cgi-sys/defaultwebpage.cgi page.  What is the problem?  I haven't set the name-servers for my domain yet, but that shouldn't be a problem because I am using the IP address in the browser.  Note: I don't think I have access to ssh.