根据来源IP跳转具体官网
编译安装Nginx 采用geoip模块
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
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 logs/access.log main;
sendfile on;
keepalive_timeout 65;
#gzip on;
geoip_country /server/tools/nginx-1.20.1/geoip/GeoIP.dat;
geoip_city /server/tools/nginx-1.20.1/geoip/GeoLiteCity.dat;
##############################################################测试 #################################################################
server {
listen 81;
server_name localhost;
root /server/tools/nginx-1.20.1/html;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
if ($geoip_country_code = CN) {
root /server/tools/nginx-1.20.1/html;
}
if ($geoip_country_code != CN) {
root /server/tools/nginx-1.20.1/html/test;
}
}
}
##############################################################英文 官网#################################################################
server {
listen 443 ssl;
server_name www..com en.ong.com;
root /ftpshare;
index index.php index.html;
ssl_certificate /server/tools/nginx-1.20.1/ssl/6543710__.com.pem;
ssl_certificate_key /server/tools/nginx-1.20.1/ssl/6543710__.com.key;
ssl_session_timeout 5m; #缓存有效期
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #加密算法
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #安全链接可选的加密协议
ssl_prefer_server_ciphers on; #使用服务器端的首选算法
location / {
root /ftpshare;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
if ($geoip_country_code = CN) {
rewrite ^/(.*) https://www.;
}
}
location ~* .*\.(jpg|gif|png)$ {
root /ftpshare;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png;
}
location ~ .*\.(jpg||jpeg|gif|png)$ {
valid_referers none blocked test.zkong.com;
if ($invalid_referer) {
return 403;
}
}
location ~ \.php$ {
root /ftpshare;
index index.php index.html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /ftpshare$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name www..com.com;
return 301 https://$server_name$request_uri;
}
##############################################################德文 官网#################################################################
server {
listen 443 ssl;
server_name de..com;
root /usr/share/nginx/html;
index index.php index.html;
ssl_certificate /server/tools/nginx-1.20.1/ssl/6543710__.pem;
ssl_certificate_key /server/tools/nginx-1.20.1/ssl/.com.key;
ssl_session_timeout 5m; #缓存有效期
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #加密算法
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #安全链接可选的加密协议
ssl_prefer_server_ciphers on; #使用服务器端的首选算法
location / {
root /usr/share/nginx/html;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
if ($geoip_country_code = CN) {
rewrite ^/(.*) https://www..cn;
}
}
location ~* .*\.(jpg|gif|png)$ {
root /usr/share/nginx/html;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png;
}
location ~ .*\.(jpg||jpeg|gif|png)$ {
valid_referers none blocked test..com;
if ($invalid_referer) {
return 403;
}
}
location ~ \.php$ {
root /usr/share/nginx/html;
index index.php index.html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
} #http区块