I have an nginx config that is similar to this:  server {   server_name my-english-site.com my-french-site.com;    listen 0.0.0.0:80;    rewrite ^ https://$server_name$request_uri? permanent; }  server {   listen 0.0.0.0:443 ssl;   server_name my-english-site.com my-french-site.com; }   When someone goes to , it redirects to , because the rewrite directive uses the first server in the $server_name directive.  I tried replacing $server_name with $host, expecting it to use the value of the Host request header. But it still redirects to the English URL.  How can I get non-HTTPS requests redirected to the corresponding HTTPS URLs?  Thank you!
82636
I want to rewrite all http requests on my web server to be https requests, I started with the following:   server {     listen      80;      location / {       rewrite     ^(.*)   https://mysite.com$1 permanent;     } ...    One Problem is that this strips away any subdomain information (e.g., node1.mysite.com/folder), how could I rewrite the above to reroute everything to https and maintain the sub-domain?
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
5141
Somehow, and I'm not sure how, we have configured an nginx reverse proxy that is acting as an open proxy.  The log files tells us the matching requests are going against the following conf file:  map $http_upgrade $connection_upgrade {         default upgrade;         ''      close; }  access_log      /var/log/nginx/access.p.log; error_log       /var/log/nginx/error.p.log;  proxy_next_upstream     error timeout invalid_header http_500 http_502 http_503 http_504; proxy_buffers           8 32k; proxy_buffer_size       64k; proxy_http_version      1.1; 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_redirect          off; proxy_set_header        Upgrade         $http_upgrade; proxy_set_header        Connection      $connection_upgrade;  server {         listen          80;         server_name     ~first.*\.second\.com;          location / {                 resolver                172.16.1.1 172.16.1.2;                 proxy_pass              http://$host;                 proxy_read_timeout      7200s;         } }  server {         listen          443;         server_name     ~first.*\.second\.com;         ssl             on;          location / {                 resolver                172.16.1.1 172.16.1.2;                 proxy_pass              https://$host;                 proxy_read_timeout      7200s;         } }   The top-level conf file looks like this:  user nginx; worker_processes 8; pid /var/run/nginx.pid;  events {         worker_connections 4096;         # multi_accept on; }  http {      ##     # Basic Settings     ##      sendfile on;     tcp_nopush on;     tcp_nodelay on;     keepalive_timeout 65;     types_hash_max_size 2048;     # server_tokens off;      # server_names_hash_bucket_size 64;     # server_name_in_redirect off;      include /etc/nginx/mime.types;     default_type application/octet-stream;      ##     # Logging Settings     ##      access_log /var/log/nginx/access.log;     error_log /var/log/nginx/error.log;      ##     # Gzip Settings     ##      gzip on;     gzip_disable "msie6";      # gzip_vary on;     # gzip_proxied any;     # gzip_comp_level 6;     # gzip_buffers 16 8k;     # gzip_http_version 1.1;     # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;      ##     # nginx-naxsi config     ##     # Uncomment it if you installed nginx-naxsi     ##      #include /etc/nginx/naxsi_core.rules;      ##     # nginx-passenger config     ##     # Uncomment it if you installed nginx-passenger     ##      #passenger_root /usr;     #passenger_ruby /usr/bin/ruby;      ##      include /etc/nginx/conf.d/*.conf;     #include /etc/nginx/sites-enabled/*;   }  what here is causing this?
75499
I have the following nginx config, e.g.  server {         listen   80;         server_name example.com         allow 127.0.0.0/8;   When I restart, it warn me:  Restarting nginx: nginx: [warn] server name "127.0.0.0/8" has suspicious  symbols in /etc/nginx/sites-enabled/xxx   Any idea?
111640
I have set $conf['reverse_proxy'] = TRUE; in settings.php, but the IP address logged in the flood table is 127.0.0.1, not the one passed through the X-Forwarded-For header. Nginx is configured to send the X-Forwarded-For header to Apache, but it seems Drupal isn't recognizing it.  This is pretty bad because a few failed logins can lockout for everyone.  How can I make Drupal use the IP passed within the X-Forwarded-For header?
67356
How would I set my webservers to work in way described below?   Http request: mypublic.com ---> handled normally by nginx as it is set up already (listen 80;) Http request: myprivate.com ---> handled by apache set up to work on 8080 (listen 8080)    I'd like to avoid including ports when typing address in browser, some kind of mockup (proxy?/squid?) at nginx. Both of domains are pointing to my machine and set up by named.
119168
I am running into a weird problem trying to disable HTTPS for one domain, but the other domain has HTTPS. They both are different websites running on a dedicated server, sharing the same IP address for the domains.  However, I have a domain that does not have a SSL certificate, but the other does. I want to disable HTTPS for the non-certified domain while leaving the other domain with HTTPS on.  I have two different separate vhosts in /etc/nginx/sites-enabled/,   domain1.org (no HTTPS)  server {      listen                      80;     server_name                 www.domain1.org domain1.org;     root                        /var/www/domain1.org;     index                       index.html index.php index.htm;      error_log                   /var/www/logs/domain1.errors.log;      [ ... ]   domain2.com (with HTTPS)  server {      listen                      443 ssl;     server_name                 domain2.com www.domain2.com;      # INCLUDE SSL CERTIFICATE     include                     sites-enabled/domain2_ssl_include;       root                        /home/domain2/www/www;     index                       index.html index.php index.htm;      [ ... ]   I've included a listener to the port 443 for domain1.org, but once I do that, I get an aborted error from Firefox saying (when accessing ):     This Connection is Untrusted      You have asked Firefox to connect securely to domain1.org, but we can't confirm that your connection is secure.   I opened the technical data, it appears that the domain1.org is using the domain2.com SSL certificate:     domain1.org uses an invalid security certificate.      The certificate is only valid for the following names:    *.domain2.com , domain2.com        (Error code: ssl_error_bad_cert_domain)   So I added this to domain1.org vhost configuration:  server {      server_name                 domain1.org www.domain1.org;      listen                      443 ssl;      rewrite ^ http://domain1.org permanent; }   Which still gets me prompted with the Firefox error.  Now... when I access to , I get an 400 error from nginx saying this:     400 Bad Request      The plain HTTP request was sent to HTTPS port   I am not entirely sure what to do, disabling the https with ssl off; has no effect. How can I actually disable HTTPS for domain1.org but not for domain2.com?  I am using Ubuntu 12.04 running nginx 1.2.6.
113909
i was wondering if nginx is able to handle http and https requests on the same port. [*]   This is what i'm trying to do. I'm running a web server (lighttpd) handling http requests, and a C program that serves a particular section of the document tree through https. These two processes run on the same server.   At the firewall level, i can have only one port forwarding traffic into this server. So what i'd like to do is to set up nginx on this server so that it listens for requests on a single port and then:  A) redirects all * requests so that they go to localhost:8080 (where lighttpd is listening)  B) if a user requests a URL starting with, for example, https:// myhost.com/app, it sends that request to localhost:8008 (C program). Note that in this case, traffic between the remote browser and nginx must be encrypted.  Do you think this could be possible? If it is, how can it be done?  I know how to do this using two different ports. The challenge that i face is doing this with just a single port (unfortunately, i don't have control over the firewall configuration on this particular environment, so that's a restriction that i cannot avoid). Using techniques like reverse port fowarding through ssh to bypass the firewall won't work either, because this should work for remote users having nothing more than a web browser and an internet link.  If this is beyond nginx capabilities, do you know of any other product that could meet this requirements? (so far i've been unsuccessful in setting this up with lighttpd and pound). I'd also prefer avoiding Apache (although i'm willing to use it if it's the only possible choice).  Thanks in advance, Alex  [*] Just to be clear, i'm talking about handling encrypted and unencrypted HTTP connections through the same port. It doesn't matter if the encryption is done through SSL or TLS.
42811
Sure I'm not the first one that tried to serve a domain example.com from a example.net/bbb, but I haven't found a solution yet.  My NGINX configuration follows the  and looks something like this:  server {     listen 80;     server_name example.net;     root /path/to/aaa;      location /bbb/ {         proxy_pass http://example.com/;         proxy_set_header Host $host;         proxy_set_header X-Real-IP $remote_addr;     }      location / {         try_files $uri $uri/ /index.html;     }     location ~ \.(svg|ttf|js|css|svgz|eot|otf|woff|jpg|jpeg|gif|png|ico)$ {         access_log off;         log_not_found off;         expires max;     } }   I can manage to render the root of example.com in example.net/bbb but:  ISSUE 1  example.net/bbb/some/path doesn't work as expected and the index.html of example.net is rendered.  ISSUE 2  Any asset in example.com/assets gives 404 because the browser look for example.net/assets. Be great if I could solve this without placing absolute paths everywhere.
31987
In my site I'm redirecting everything (http://, http://www., https://) to https://www.example.com.  Google webmaster tools says: Make sure you add both "www" and "non-www" versions for your site. Also, if you use the HTTPS protocol, add those variations as well.  So I've added all the FOUR versions to google webmaster tools. Is this a correct process?
78999
I have a brand new VM with CenotOS 7 Minimal Installation.  What I want to happen is to configure Nginx to serve static files from a directory on localhost:80.  My directory is /home/kenny/projects/kcrypt/dist/.  Here are the contents of my /etc/nginx/nginx.conf:  # this is set to root in order to rule out # any permission related issues. user root;      worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid;  include /usr/share/nginx/modules/*.conf;  events {     worker_connections 1024; }  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;      include             /etc/nginx/mime.types;     default_type        application/octet-stream;      server {         listen       80 default_server;         listen       [::]:80 default_server;         root         /home/kenny/projects/kcrypt/dist/;         index index.html;          location / {         }     } }   when I run curl http://localhost I get this response:  &lt;html&gt; &lt;head&gt;&lt;title&gt;403 Forbidden&lt;/title&gt;&lt;/head&gt; &lt;body bgcolor="white"&gt; &lt;center&gt;&lt;h1&gt;403 Forbidden&lt;/h1&gt;&lt;/center&gt; &lt;hr&gt;&lt;center&gt;nginx/1.12.2&lt;/center&gt; &lt;/body&gt; &lt;/html&gt;   I have tried giving all kinds of permissions to any directories that I can think of.   In the end I configured Nginx to run as root.   I have reinstalled the OS multiple times already and can't get it to work.   P.S.   This is what I found in /var/log/nginx/error.log  2018/02/27 21:33:19 [error] 15689#0: *1 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost" 2018/02/27 21:33:35 [error] 15690#0: *2 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1" 2018/02/27 21:33:38 [error] 15690#0: *3 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"   I don't get what it wants... I have given it all the permissions that I can.   This is what I have in the root directory:  [root@vm3 dist]# ll total 368K drwxrwxrwx. 2 root root   98 Feb 26 23:16 . drwxrwxrwx. 6 root root  234 Feb 27 21:26 .. -rwxrwxrwx. 1 root root 1.2K Feb 26 23:16 favicon.ico -rwxrwxrwx. 1 root root 1.7K Feb 26 23:16 index.html -rwxrwxrwx. 1 root root 175K Feb 26 22:53 index.js -rwxrwxrwx. 1 root root  297 Feb 26 23:16 manifest.json -rwxrwxrwx. 1 root root 179K Feb 26 22:53 styles.css   P.S. 2  I have tried putting my static files in /var/www/kcrypt/dist/, but with no result.  I still get the same error messages:   2018/02/27 23:18:11 [error] 16157#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost" 2018/02/27 23:20:58 [error] 16535#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost" 2018/02/27 23:21:30 [error] 16564#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"
56911
I've been working with Apache http servers for quite some time, and finally making the move to static-content servers alongside the others dynamic-content machines.   I was wondering, does nginx support ".htaccess" files, and things like mod_rewrite?   As I'm very used to the syntax, I was wondering what the (syntax) differences were, and what the learning curve is like moving from Apache configs to nginx.
25732
I have one nginx server setup(two config files) with two gunicorn web servers setup and running. One gunicorn is production and the other is staging.   I want nginx to serve http requests to xyz.com as well as https requests to xyz.com to the production gunicorn server @ 127.0.0.1:8000.    I have accomplished this with:  server {    listen 80;    server_name xyz.com;    return 301 https://$http_host$request_uri; }  server {    listen 443 ssl;    server xyz.com;    ..... &lt;&lt;&lt; ssl stuff   location /{       .... proxy_stuff       proxy_pass http://127.0.0.1:8000;   } }   I also want http traffic to xyz.com:8080 and https traffic to xyz.com:8080 to hit the staging server @ 127.0.0.1:8081. I have been been able to get https traffic to xyz.com:8080 working as follows:  server {    listen 8080 ssl;    server_name xyz.com;    ...... &lt;&lt; ssl stuff    location / {       ...... &lt;&lt; proxy stuff       proxy_pass http://127.0.0.1:8081;    } }   But I can't seem to find a way to redirect http traffic at xyz.com:8080 to https traffic at xyz.com:8080. I have tried the same redirection that I did with port 80 but have not been successful.   Could use some direction.
23776
I've checked out quite a few other answers to similar questions as well as tutorials on DigitalOcean, etc., with no success. Sorry for what is probably a very obvious problem - I'm new to this.  Essentially, I need to set up redirects so that http://, ., and . all redirect to https://.  Currently, https:// works fine and http:// redirects to https://. I need to redirect www traffic because the SSL cert is only configured for non-www. However, when I've tried to add another server block to the config to redirect www (http and https) to https://, the server closes the connection on all 4 variants.  Here's my config:  # HTTP - redirect to HTTPS server {     listen 80;     server_name www.example.com example.com;     return 301 https://example.com$request_uri; }  # HTTPS www - redirect to non-www RESETS CONNECTION #server { #    listen 443; #    server_name www.example.com; #    return 301 https://example.com$request_uri; #}   # HTTPS — proxy all requests to the Node app server {     # Enable HTTP/2     listen 443 ssl http2;     server_name example.com;      # Use the Let’s Encrypt certificates     ssl_certificate /etc/not/my/path/live/example.com/fullchain.pem;     ssl_certificate_key /etc/not/my/path/live/example.com/privkey.pem;      # Include the SSL configuration from cipherli.st     include snippets/ssl-params.conf;      location / {         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header X-NginX-Proxy true;         proxy_pass http://0.0.0.0:2368/;         proxy_ssl_session_reuse off;         proxy_set_header Host $http_host;         proxy_cache_bypass $http_upgrade;         proxy_redirect off;     } }   Can anyone tell me what I'm doing wrong? Again I know it's probably painfully obvious but I just can't get this to work. Should I be doing this with something other than an NGINX redirect?
26009
I'm currently trying to set up a small static website with my domain from NameCheap using AWS S3, but I'm having trouble correctly pointing requests to the corresponding S3 bucket.  These are my configurations for the services I use:  NameCheap  CNAME         www  example.com.s3-website-ap-northeast-1.amazonaws.com. URL Redirect  @    http://www.example.com/   AWS S3  Static Hosting example.com.s3-website-ap-northeast-1.amazonaws.com.   I am fairly new to web hosting/domain stuff so please bear with me, but from what I understand from my registrar configuration is: users entering the naked domain example.com are redirected to www.example.com which then points to the AWS S3 bucket. Then the CNAME record then points to the corresponding AWS bucket.  Howeverwhen I try to visit www.example.com I somehow get pointed to the www.example.com bucket instead of the example.com bucket landing me to the AWS Bucket not found page.  Extra Details   I've checked with DNS Checker that www.example.com's CNAME record indeed points to example.com.s3-website-ap-northeast-1.amazonaws.com.. I've also tried making a www.example.com bucket then redirecting it to example.com but it seems it points to the actual domain instead of the bucket therefore causing a redirect loop. example.com-&gt;www.example.com-&gt;www.example.com (Bucket)-&gt;example.com-&gt;∞
105322
I have few different vhost created and every one has its own folder in /var/www/ like this /var/www/example1/ /var/www/example2/  Now, when I type url with www www.example1.com it points to the /var/www/example1/index.html so that's working fine, but when I type without www example1.com it points to /var/www/ and I can see all the folders, I don't have index.html in /var/www/. I looked  and created .htaccess in /var/www/:     RewriteEngine On     RewriteBase /     RewriteCond % ^example1.com [NC]     RewriteRule ^(.*)$ http://www.example1.com/$1 [L,R=301]  but it's not working. This is how the all vhosts look like: &lt;VirtualHost *:80&gt;         ServerAdmin webmaster@localhost         ServerName *example1*         ServerAlias *.*example1*         DocumentRoot /var/www/example1         &lt;Directory /&gt;                 Options FollowSymLinks                 AllowOverride All         &lt;/Directory&gt;         &lt;Directory /var/www/example1/&gt;                 Options Indexes FollowSymLinks MultiViews                 AllowOverride All                 Order allow,deny                 allow from all         &lt;/Directory&gt;          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/         &lt;Directory &quot;/usr/lib/cgi-bin&quot;&gt;                 AllowOverride None  I have cleared browser cache. Any idea how to fix this?
5392
When using the ssh or ftp commands from the Bash shell, does the server that I am connecting to learn of the domain name used? I understand that the domain name is locally translated into an IP address via DNS. In HTTP, after that happens, the server is told the original domain name as well in order to serve the correct page, or to present the correct TLS cert (SNI).  host serverfault.com GET /   Does a similar phenomenon happen when connecting to ssh or ftp?  I ask because I am  trying to ssh into a server (GoDaddy webhosting) which expects a domain name, but is not letting me in when I try to connect via user@IPaddress as the DNS is not yet moved to the GoDaddy IP address.