Nginx 同一台服务器上配置多个二级域名

﹏ヽ暗。殇╰゛Y 2022-02-19 00:19 427阅读 0赞

Nginx 同一台服务器上配置多个二级域名

需要多个二级域名访问同一台服务器
blog.8023.xin
bt.8023.xin
解决方案 Nginx 进行监听不同域名,进行端口转发

核心配置

  1. listen 888;
  2. server_name *.8023.xin;
  3. if ( $http_host ~* "^(.*?)\.a\.cn" ) {
  4. set $domain $1;
  5. }
  6. location / {
  7. proxy_set_header X-Real-IP $remote_addr;
  8. proxy_set_header Host $http_host;
  9. if ( $domain ~* "blog" ) {
  10. proxy_pass http://127.0.0.1:80;
  11. }
  12. if ( $domain ~* "bt" ) {
  13. proxy_pass http://127.0.0.1:8888;
  14. }
  15. }

完整配置

  1. user www www;
  2. worker_processes auto;
  3. error_log /www/wwwlogs/nginx_error.log crit;
  4. pid /www/server/nginx/logs/nginx.pid;
  5. worker_rlimit_nofile 51200;
  6. events
  7. {
  8. use epoll;
  9. worker_connections 51200;
  10. multi_accept on;
  11. }
  12. http
  13. {
  14. include mime.types;
  15. #include luawaf.conf;
  16. include proxy.conf;
  17. default_type application/octet-stream;
  18. server_names_hash_bucket_size 512;
  19. client_header_buffer_size 32k;
  20. large_client_header_buffers 4 32k;
  21. client_max_body_size 50m;
  22. sendfile on;
  23. tcp_nopush on;
  24. keepalive_timeout 60;
  25. tcp_nodelay on;
  26. fastcgi_connect_timeout 300;
  27. fastcgi_send_timeout 300;
  28. fastcgi_read_timeout 300;
  29. fastcgi_buffer_size 64k;
  30. fastcgi_buffers 4 64k;
  31. fastcgi_busy_buffers_size 128k;
  32. fastcgi_temp_file_write_size 256k;
  33. fastcgi_intercept_errors on;
  34. gzip on;
  35. gzip_min_length 1k;
  36. gzip_buffers 4 16k;
  37. gzip_http_version 1.1;
  38. gzip_comp_level 2;
  39. gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
  40. gzip_vary on;
  41. gzip_proxied expired no-cache no-store private auth;
  42. gzip_disable "MSIE [1-6]\.";
  43. limit_conn_zone $binary_remote_addr zone=perip:10m;
  44. limit_conn_zone $server_name zone=perserver:10m;
  45. server_tokens off;
  46. access_log off;
  47. server
  48. {
  49. listen 888;
  50. server_name *.8023.xin;
  51. if ( $http_host ~* "^(.*?)\.a\.cn" ) {
  52. set $domain $1;
  53. }
  54. location / {
  55. proxy_set_header X-Real-IP $remote_addr;
  56. proxy_set_header Host $http_host;
  57. if ( $domain ~* "blog" ) {
  58. proxy_pass http://127.0.0.1:80;
  59. }
  60. if ( $domain ~* "bt" ) {
  61. proxy_pass http://127.0.0.1:8888;
  62. }
  63. }
  64. index index.html index.htm index.php;
  65. root /www/server/phpmyadmin;
  66. #error_page 404 /404.html;
  67. include enable-php.conf;
  68. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  69. {
  70. expires 30d;
  71. }
  72. location ~ .*\.(js|css)?$
  73. {
  74. expires 12h;
  75. }
  76. location ~ /\.
  77. {
  78. deny all;
  79. }
  80. access_log /www/wwwlogs/access.log;
  81. }
  82. include /www/server/panel/vhost/nginx/*.conf; }

发表评论

表情:
评论列表 (有 0 条评论,427人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Nginx配置二级域名

    当一个域名需要使用在两个项目上后,我们就需要使用到二级域名,在 Nginx 中配置二级域名如下: 1、原始配置文件如下 worker_processes 1;