golang - nginx as reverse proxy go as server cannot read static files
大家讲道理
大家讲道理 2017-05-16 17:16:46
0
1
1103

There is the following code in the website html:

   

The problem now is that the browser cannot read these files
Use go as the server and nginx as the reverse proxy
The html files are placed in the /home/user/project/ directory
static and other folders Also placed in this directory
/home/user/project/ is the project root directory

nginx has made the following configuration

location /static/ { alias /home/user/project/static/; }

But it doesn’t feel like it’s working

How can I make the browser correctly find the specified file without modifying the original code of the web page?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all (1)
刘奇

Let me give you an nginx configuration file of beego for your reference. The general principle is that in addition to specifying the css, js, fonts, and img characters in the URL, nginx takes over. If the file does not exist, it will be forwarded to the backend request, which is equivalent to the web opened by GO. Server

server { listen 80; server_name .a.com; charset utf-8; access_log /home/a.com.access.log; location /(css|js|fonts|img)/ { access_log off; expires 1d; root "/path/to/app_a/static"; try_files $uri @backend; } location / { try_files /_not_exists_ @backend; } location @backend { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:8080; } }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!