我在Rackspace云上使用nginx,遵循一个教程,搜索了网络,到目前为止还不能得到这个排序。
我想要www.mysite.example去mysite。例如,正常的。htaccess为SEO和其他原因。
My /etc/nginx/sites-available/www.example.com.vhost config:
server {
listen 80;
server_name www.example.com example.com;
root /var/www/www.example.com/web;
if ($http_host != "www.example.com") {
rewrite ^ http://example.com$request_uri permanent;
}
我也试过
server {
listen 80;
server_name example.com;
root /var/www/www.example.com/web;
if ($http_host != "www.example.com") {
rewrite ^ http://example.com$request_uri permanent;
}
我也试过。第二次尝试都给出重定向循环错误。
if ($host = 'www.example.com' ) {
rewrite ^ http://example.com$uri permanent;
}
我的DNS设置为标准:
site.example 192.192.6.8 A type at 300 seconds
www.site.example 192.192.6.8 A type at 300 seconds
(示例ip和文件夹已用于示例和帮助人们在未来)。我使用Ubuntu 11。
我的配置是- Nginx + tomcat 9 + Ubuntu 20.04 + spring boot app
上面所有的答案都不适合我-也不适合Nginx文件中的上游符号-所以我改变了我的设置
感谢上帝的certbot -这个util非常有用,它为您的网站生成基本文件,然后我添加了我的更改-重定向https://www.example.com, http://www.example.com到只有一个https://example.com
server {
if ($host = www.example.com) {
return 301 https://example.com$request_uri;
}
root /var/www/example.com/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080; # This is upstream name, note the variable $scheme in it
proxy_redirect off;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://example.com$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 404; # managed by Certbot
}