VPS侦探论坛

 找回密码
 注册
查看: 4125|回复: 1

[Apache] 一个网站多个域名怎么配置?

[复制链接]
发表于 2018-10-16 09:18:30 | 显示全部楼层 |阅读模式

网站原来的域名 www.example1.com:配置如下
  1. server{
  2. listen 80;
  3. server_name www.example1.com example1.com;
  4. index index.html index.htm  index.php;
  5. root /alidata1/web/www.example1.com;
  6. access_log off;
  7. error_page 404 /404.html;
  8. #error_page 403 /403.html;
  9. if ($scheme = http ) {
  10.      return 301 https://$host$request_uri;
  11.     }
  12. }

  13. server {
  14.   listen 443 ssl http2;
  15.   server_name example1.com www.example1.com
  16.   access_log off;
  17.   index index.html index.php;
  18.   root /alidata1/web/www.example1.com;

  19. if ($host = 'example1.com') {  return 301 https://www.example1.com$request_uri;  }

  20. # 阻止扫描器
  21.   if ($bad_bot) {
  22.         return 403;
  23.     }

  24.   if ($request_method !~ ^(GET|HEAD|POST)$) {
  25.           return 444;
  26.         }

  27.    http2_push_preload on;
  28.   
  29.   error_page 404 /404.html;
  30.   #error_page 502 /502.html;

  31.   ssl on;
  32.   ssl_stapling on;
  33.   ssl_stapling_verify on;
  34.   ssl_trusted_certificate  /etc/letsencrypt/acme/fullchain.cer;
  35.   ssl_certificate   /etc/letsencrypt/acme/fullchain.cer;
  36.   ssl_certificate_key /etc/letsencrypt/acme/*.example1.com.key;
  37.   ssl_session_timeout 15m;
  38.   ssl_session_cache shared:SSL:50m;
  39.   #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  40.    ssl_protocols  TLSv1.1 TLSv1.2 TLSv1.3;
  41.   ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
  42.   ssl_prefer_server_ciphers on;


  43.   location ~ [^/]\.php(/|$) {
  44.     #fastcgi_pass remote_php_ip:9000;
  45.     fastcgi_pass unix:/dev/shm/php-cgi.sock;
  46.     fastcgi_index index.php;
  47.     include fastcgi.conf;
  48.   }

  49.      # resolve cros
  50.   location ~* \.(eot|ttf|woff|woff2|svg|otf|css|js) {
  51.     add_header Access-Control-Allow-Origin *;

  52.   }


  53.   # cache .html files
  54.   location ~.*\.(html|xml|json)$ {
  55.     expires 30d;
  56.   }
  57.   # cache images files
  58.   location ~ .*\.(webm|webp|gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico|html)$ {
  59.     expires 360d;
  60.     access_log off;
  61.     log_not_found off;
  62.   }
  63.   # cache js,css files
  64.   location ~ .*\.(js|css)?$ {
  65.     expires 360d;
  66.     access_log off;
  67.     log_not_found off;
  68.   }
  69. }
复制代码



现在想增加一个域名访问 example2.com 改成如下配置:


  1. server{
  2. listen 80;
  3. server_name www.example1.com example1.com www.example2.com example2.com;
  4. index index.html index.htm index.php;
  5. root /alidata1/web/www.example1.com;
  6. access_log off;
  7. error_page 404 /404.html;
  8. #error_page 403 /403.html;
  9. if ($scheme = http ) {
  10. return 301 https://$host$request_uri;
  11. }
  12. }

  13. server {
  14. listen 443 ssl http2;
  15. server_name example1.com www.example1.com www.example2.com example2.com;
  16. access_log off;
  17. index index.html index.php;
  18. root /alidata1/web/www.example1.com;

  19. if ($host = 'example1.com') { return 301 https://www.example1.com$request_uri; }if ($host = 'example2.com') { return 301 https://www.example2.com$request_uri; }

  20. # 阻止扫描器
  21. if ($bad_bot) {
  22. return 403;
  23. }

  24. if ($request_method !~ ^(GET|HEAD|POST)$) {
  25. return 444;
  26. }

  27. http2_push_preload on;

  28. error_page 404 /404.html;
  29. #error_page 502 /502.html;

  30. ssl on;
  31. ssl_stapling on;
  32. ssl_stapling_verify on;
  33. ssl_trusted_certificate /etc/letsencrypt/acme/fullchain.cer;
  34. ssl_certificate /etc/letsencrypt/acme/fullchain.cer;
  35. ssl_certificate_key /etc/letsencrypt/acme/*.example1.com.key;
  36. ssl_session_timeout 15m;
  37. ssl_session_cache shared:SSL:50m;
  38. #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  39. ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
  40. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
  41. ssl_prefer_server_ciphers on;


  42. location ~ [^/]\.php(/|$) {
  43. #fastcgi_pass remote_php_ip:9000;
  44. fastcgi_pass unix:/dev/shm/php-cgi.sock;
  45. fastcgi_index index.php;
  46. include fastcgi.conf;
  47. }

  48. # resolve cros
  49. location ~* \.(eot|ttf|woff|woff2|svg|otf|css|js) {
  50. add_header Access-Control-Allow-Origin *;

  51. }


  52. # cache .html files
  53. location ~.*\.(html|xml|json)$ {
  54. expires 30d;
  55. }
  56. # cache images files
  57. location ~ .*\.(webm|webp|gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico|html)$ {
  58. expires 360d;
  59. access_log off;
  60. log_not_found off;
  61. }
  62. # cache js,css files
  63. location ~ .*\.(js|css)?$ {
  64. expires 360d;
  65. access_log off;
  66. log_not_found off;
  67. }
  68. }
复制代码



*.example1.com 和*.example2.com的证书公用。
配置之后可以访问www.example2.com 但是页面加载到一定时间之后,URL又自己跳到www.example1.com
所以,我的配置应该怎么改一下?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2018-10-16 17:39:05 | 显示全部楼层


不大清楚
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-5-5 11:09 , Processed in 0.025665 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表