如何使用Gitlab页面和Nginx反向代理服务静态文件夹?

时间:2019-05-22 01:46:48

标签: javascript nginx proxy gitlab-pages react-styleguidist

我正在使用react-styleguidist使用markdown编写文档。

我有以下标记:

- `guideline.pdf` [![pdf icon](/static/pdficon.png)](/static/annex/website/guideline.pdf)

这在开发中工作正常,但是由于Gitlab-Page是在子路径下提供的,因此我在生产中遇到了问题。

它尝试获取http://myapp.com/communication/static/pdficon.png而不是获取http://myapp.com/static/pdficon.png,结果是404。

这是我的nginx反向代理配置:

# configuration file /etc/nginx/upstream-conf/default-with-host-non-ssl.conf:
proxy_pass http://$upstream;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 900;
proxy_send_timeout 900;
# configuration file /etc/nginx/sites-enabled/wildcard.myapp.com.conf:
server {
  listen 80;

  server_name  ~^(?<group>.*)\.myapp\.com$;
  server_tokens off;
  disable_symlinks on;
  location / {
    auth_basic_user_file             /etc/nginx/htpasswd/page-yeutech/.htpasswd;
    proxy_intercept_errors on;
    location /img {
      try_files $uri /img/default.jpg;
    }

    set $upstream 192.168.2.45:31581;
    include /etc/nginx/upstream-conf/default-with-host-non-ssl.conf;
  }

  error_page 404 /404.html;

  location = /404.jpg {
    root /var/www/wildcard.myapp.com/html;
  }

  location = /404.html {
    root /var/www/wildcard.myapp.com/html;
    internal;
  }

  ## Individual nginx logs for this GitLab vhost
  access_log  /var/log/nginx/wildcard-www-myapp-com_access.log;
  error_log   /var/log/nginx/wildcard-www-myapp-com_error.log;
}

为了方便开发和生产,我宁愿不更改文件中的synthax来设置完整网址。

如何优雅地解决此问题?

0 个答案:

没有答案