Nginx cannot access static resources. Nginx does not have a port to access static resources, so static resources cannot be accessed. After intranet penetration, local static resource files js css cannot be accessed.

After using the intranet penetration, a free second-level domain name will be generated. This domain name + remote server port can be mapped to the local port.

For example: http://cn-2.openfrp.top:8888 8888 is the remote server port mapping local port 80;

Wrong Nginx configuration such as

server {
    listen 80;
    server_name test-emlog.com;
    root /www/wwwroot/emlog;
    index index.html index.htm index.php;

    location /blog {
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:89/;
    }

    location ~* \.(eot|ttf|woff|svg|otf)$ {
        add_header Access-Control-Allow-Origin *;
    }
}

According to the above configuration, when we enter http://cn-2.openfrp.top:8888/blog in the browser, we will find that all static resources cannot be loaded; as shown in the figure
Insert image description here

wrong reason

But when we copy the failed connection and add port 8888, we will find that it can be accessed normally;
Cause of the error: The remote server port is not reached when requesting static files.< /span>

The reason is found. Then the point of configuration error is found:
proxy_set_header Host h o s t : host: host:server_port;

This is caused by a configuration error

solution

​修改 proxy_set_header Host h o s t : host: host:server_port; is proxy_set_header Host $http_host;
The modified content is as follows

server {
    listen 80;
    server_name test-emlog.com;
    root /www/wwwroot/emlog;
    index index.html index.htm index.php;

    location /blog {
        proxy_set_header Host $http_host;  //只修改这一行
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:89/;
    }

    location ~* \.(eot|ttf|woff|svg|otf)$ {
        add_header Access-Control-Allow-Origin *;
    }
}

proxy_set_header common configuration explanation

Take the configuration in this article as an example. The values ​​of some variables

variable value in this article illustrate
$host cn-2.openfrp.top Without http https prefix
$http_host cn-2.openfrp.top:8888 Without http https prefix
$server_port 80 listen value
$proxy_host 89 proxy_pass value

Guess you like

Origin blog.csdn.net/guzhizang/article/details/133910405
Recommended