서버/개발환경

nginx로 멀티도메인

아카이sun 2018. 9. 6. 17:03

하나의 서비스에서 접속방법을 달리하고싶을때.


default.conf의 설정



server {

listen 80 default_server;

listen [::]:80 default_server;


  server_name  www.site.com;

  

  access_log  /var/log/nginx/blog.access.log;

  error_log  /var/log/nginx/blog.error.log;


  index index.php index.html index.htm index.nginx-debian.html;


  root /var/www;

  

  location / {

      

  }

  

  location /path {

    try_files $uri $uri/ /path/index.php?/$request_uri;

  }


  location ~ \.php$ {

      try_files $uri =404;

      fastcgi_split_path_info ^(.+\.php)(/.+)$;

      fastcgi_pass   unix:/run/php/php7.0-fpm.sock;

      fastcgi_index  index.php;

      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

      include        fastcgi_params;

  }


  location ~ /\.ht {

      deny all;

  }

}


여기에 www대신 다른 prefix를 붙이고 싶다면??


api.conf를 만들어서 작성한다.



server {

  listen 80;


  server_name  api.site.com;

  

  if ($request_uri ~ "/path/sub_path/(.*)"){

    return 301 http://www.site.com$request_uri;

  }

}