我想为我的网站创建重定向规则,
我想将我的网站从 ip 重定向到域名,但它在非 https 中工作正常,但是当我输入https://id-地址它按原样打开,无需重定向。
这是我的配置文件。
# HTTP server
server {
listen 80;
server_name localhost;
#include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";
include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf";
}
# HTTPS server
server {
listen 443 ssl;
server_name example.com;
ssl_certificate example.com.crt;
ssl_certificate_key example.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";
include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf";
}
include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-vhosts.conf";
# Status
server {
listen 80;
server_name local-stackdriver-agent.stackdriver.com;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location / {
root /dev/null;
}
}
server {
server_name 123.456.789.100 www.example.com example.com;
return 301 https://example.com$request_uri;
}
答案1
虽然理论上可行,但实际上你无法轻易为 IP 地址创建 https 证书。如果你真的需要这样做,你可以找一个证书颁发机构来帮你做这件事,但我认为在大多数情况下,你最好找到另一种解决方案或以不同的方式看待你的问题。