OMG! I just solved problem just change this return 301 https://example.dev$request.uri;
to this value return 301 https://example.dev$request_uri;
More specifically request.uri was invalid !!!
My aim is to redirect all requests to the https://example.dev
http://example.dev
successfully redirects to thehttps://example.dev
http://www.example.dev
successfully redirects to thehttps://example.dev
https://www.example.dev
fails when redirecting to thehttps://example.dev
In the firefox:
An error occurred during a connection to www.example.dev.
The page you are trying to view cannot be shown because an error in the data transmission was detected.
Please contact the website owners to inform them of this problem.
GoogleChrome redirects to the https://example.devget%20/%20HTTP/2.0.uri
. And fails again.
Here is the my nginx configuration:
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
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;
...
...
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name www.example.dev example.dev;
return 301 https://example.dev;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 443 ssl http2;
server_name www.example.dev;
ssl_certificate /etc/letsencrypt/live/example.dev/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.dev/privkey.pem;
return 301 https://example.dev$request.uri;
}
server {
listen 443 ssl http2;
server_name example.dev;
ssl_certificate /etc/letsencrypt/live/example.dev/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.dev/privkey.pem;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
}