nginx 一个域名 几个网站

nginx 一个域名 几个网站

我在为一个域名上的几个页面配置 nginx 时遇到了问题。例如,我们有 example.com。这个页面允许您购买一些商品,但我想将页面按大洲分开。所以我创建了 /usr/share/nginx/europe、/usr/share/nginx/asia,每个文件夹都有自己的文件、数据库等。我正在尝试配置它,但我不知道该怎么做。我应该创建一些子域名吗?我不能使用例如:example.com/asia example.com/europe 在 /etc/nging/sites-enabled 中,我创建了两个文件 europe 和 asia:

server {
   listen   80;
   root /usr/share/nginx/europe; 
   index index.html index.htm index.php;
   server_name example.com/europe;
   access_log /var/log/nginx/test1_access.log;
   error_log /var/log/nginx/test1_error.log;

   location /blog.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
    }
}

server {
    listen   80;
    root /usr/share/nginx/asia; 
    index index.html index.htm index.php;
    server_name example.com/asia;
    access_log /var/log/nginx/asia_access.log;
    error_log /var/log/nginx/asia_error.log;

    location /blog.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
    }
}

答案1

您不能将 server_name 与 URI 元素一起使用。尝试一下

server {
   listen   80;
   server_name example.com;



    location /europe/ {
      root /usr/share/nginx/europe; 
      index index.html index.htm index.php;
      access_log /var/log/nginx/test1_access.log;
      error_log /var/log/nginx/test1_error.log;

      location ~* \blog.php$ {
          include /etc/nginx/fastcgi_params;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
      }
    }

    location /asia/ {
      root /usr/share/nginx/asia; 
      index index.html index.htm index.php;
      access_log /var/log/nginx/asia_access.log;
      error_log /var/log/nginx/asia_error.log;

      location ~* \blog.php$ {
          include /etc/nginx/fastcgi_params;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
      }
    }
}

相关内容