Getting Nginx to point to a specific index.html pa

2019-06-10 05:18发布

问题:

I'm trying to get nginx to point to my index.html page along with imgs, CSS, JS, etc. that lies in a GoPATH, which is outside of /var/www/. My overall objective is to allow my website to run on port 80 and not 8080. Is it possible to do this? Below is what I currently have in the nginx.conf.

user www-data;

    http {
            include /etc/nginx/proxy.conf;
            index   index.html
    }

                  server { # simple reverse-proxy
            listen       80;
            server_name  dtrinh.com www.dtrinh.com;
            access_log   logs/dtrinh.access.log  main;

            # serve static files
            # serve static files
            location /  {
              root    /go/src/ps/views/default/index.html;
              expires 30d;

            # pass requests for dynamic content to rails/turbogears/zope, et al
            location / {
              proxy_pass      http://127.0.0.1:8080;
            }

        }

回答1:

location / {
    root /go/src/ps/views/default;
    error_page 404 = @backend;
    expires 30d;
}

location @backend {
    proxy_pass http://127.0.0.1:8080;
}

Reference:

  • http://nginx.org/r/root
  • http://nginx.org/r/error_page
  • http://nginx.org/r/location