我已经在 NGINX 上完成了重定向,但它仍然不起作用。
首先,我需要重定向http://www.example.com到https://www2.example.com
另外,重定向https://www.example.com到https://www2.example.com
我有以下配置:
[root@andysrv5-nginx ~]# cat /etc/nginx/nginx.conf
user nginx;
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;
error_log /var/log/nginx/error.log debug;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
###### setting for crm.example.com http
server {
listen 80;
server_name crm.example.com;
access_log off;
location / {
proxy_pass http://172.31.16.207/;
proxy_redirect off;
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_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
###### setting for crm.example.com https
server {
listen 443 ssl http2;
server_name crm.example.com;
server_tokens off;
access_log off;
ssl_certificate "/etc/pki/nginx/fullchain-1657107464.pem";
ssl_certificate_key "/etc/pki/nginx/privkey-1657107464.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5:!EXPORT:!DES;
ssl_prefer_server_ciphers on;
location / {
proxy_pass https://172.31.16.207/;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
}
if ($request_method !~ ^(GET|HEAD|POST)$ )
{
return 405;
}
}
###### setting for www2.example.com http
server {
listen 80;
server_name www.example.com;
return 301 https://www2.example.com$request_uri;
}
server {
listen 80;
server_name www2.example.com;
return 301 https://www2.example.com$request_uri;
}
###### setting for www2.example.com https ####################
server {
listen 443 ssl http2;
server_name www.example.com;
return 301 https://www2.example.com$request_uri;
}
server {
listen 443 ssl http2;
server_name www2.example.com;
server_tokens off;
ssl_certificate "/etc/pki/nginx/www2.certificate.crt";
ssl_certificate_key "/etc/pki/nginx/www2.private.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5:!EXPORT:!DES;
ssl_prefer_server_ciphers on;
location / {
proxy_pass https://10.10.10.209/;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
}
if ($request_method !~ ^(GET|HEAD|POST)$ )
{
return 405;
}
}
}
你能帮我解决我做错的事吗?!!