
Alterei meu arquivo conf para que quando um usuário digitar no domínio sem www ele redirecione para o domínio com www:
nome_servidor exemplo.com; return 301 $esquema://www.example.com$request_uri; Também desejo meu https para qualquer coisa em/user
Recebo o erro de muitos redirecionamentos, onde estou errando?
Então eu tenho:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/example.com/site;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /user {
rewrite ^ https://$http_host$request_uri? permanent;
}
}
Para porta 443:
server {
listen 443;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
root /var/www/example.com/site;
index index.html index.htm;
ssl on;
ssl_certificate //path here
ssl_certificate_key //path here
location / {
rewrite ^ http://$http_host$request_uri? permanent;
}
location /user {
}
}
Responder1
A melhor maneira de fazer isso é ter server
blocos separados para example.com
e www.example.com
. A entrada para example.com
deveriaapenaster:
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
A entrada para www.example.com
terá todo o resto (e obviamentenãotem o redirecionamento).
Da mesma forma, você terá duas entradas de servidor separadas para https (porta 443).
Responder2
Eu faria algo assim: (não testado)
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
listen 80;
server_name www.example.com;
root /var/www/example.com/site;
index index.html index.htm;
location / {
rewrite ^/index.php;
}
}
server {
listen 443;
server_name www.example.com;
root /var/www/example.com/site;
index index.html index.htm;
ssl on;
ssl_certificate //path here
ssl_certificate_key //path here
location /user {
rewrite ^ https://$http_host$request_uri? permanent;
}
}