Enable nginx to access another web root dir on centos

By default, it will complain with a 403 Forbidden page if simply changing the root in nginx config to somewhere else. This is usually caused by two issues:

  1. directory ownerships and permissions
  2. SELinux configs

For my case, it’s the SELinux. In short, I just put the necessary commands here:

$ sudo chcon -Rt httpd_sys_content_t /PATH/TO/NEW/HTML
# usually this will be enough, but in case it doesn't, especially when there is proxy_pass in the settings, add the following one as well
$ sudo setsebool -P httpd_can_network_connect on

For more details, check the answers in this question on stackoverflow.