nginxがマルチドメイン名をどのように構成するかについて【httpまたはhttpsドメイン間】ドメイン間【注意:*ワイルドカードすべてのドメイン名ドメイン間で有効にならない場合があります.指定したマルチドメイン名ドメイン間構成を使用することをお勧めします】
3808 ワード
重点nginxドメイン間参照:https://www.cnblogs.com/gaoyuechen/p/12880939.html
注意:add_header Access-Control-Allow-Origin *; ワイルドカードはすべてのドメイン名がnginxで無効になるように構成します.複数回のテストは依然としてそうです.指定したマルチドメイン名を使用してドメインをまたぐことをお勧めします.
【ドメイン間で成功した構成】マルチドメイン名構成ドメイン間での構成を指定します.
一般的なリファレンス:https://www.cnblogs.com/iLoveMyD/p/10276359.html
一般的なリファレンス:https://www.cnblogs.com/yuanwanli/p/12670838.html
注意:add_header Access-Control-Allow-Origin *; ワイルドカードはすべてのドメイン名がnginxで無効になるように構成します.複数回のテストは依然としてそうです.指定したマルチドメイン名を使用してドメインをまたぐことをお勧めします.
【ドメイン間で成功した構成】マルチドメイン名構成ドメイン間での構成を指定します.
# 【nginx * , , , ...】
set $cors_origin "";
if ($http_origin ~* "^https://aaaa.org$") {
set $cors_origin $http_origin;
}
if ($http_origin ~* "^https://www.aaaa.org$") {
set $cors_origin $http_origin;
}
# http https !
add_header Access-Control-Allow-Origin $cors_origin;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
# nformation on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# on !:
daemon on;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
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;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
# 443 ( )
listen 443 ssl;
server_name aaaa.org www.aaaa.org;
index index.html index.htm;
root /root/www/t.radarleb.org;
# ( , conf/ssl , )
ssl_certificate ssl/aaaa.org.crt;
ssl_certificate_key ssl/aaaa.org.key;
# ( , https , )
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# HTTPS( , )
if ($server_port = 80){
rewrite ^(/.*)$ https://$host$1 permanent;
}
# 【nginx * , , , ...】
set $cors_origin "";
if ($http_origin ~* "^https://aaaa.org$") {
set $cors_origin $http_origin;
}
if ($http_origin ~* "^https://www.aaaa.org$") {
set $cors_origin $http_origin;
}
# http https !
add_header Access-Control-Allow-Origin $cors_origin;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
error_page 404 /404.html;
location = /usr/share/nginx/html/40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /usr/share/nginx/html/50x.html {
}
}
}
一般的なリファレンス:https://www.cnblogs.com/iLoveMyD/p/10276359.html
一般的なリファレンス:https://www.cnblogs.com/yuanwanli/p/12670838.html