When accessing the front end, a 403 Forbidden problem is reported

Handling 403 Forbidden issues

Table of contents

1. Insufficient authority resources

2. The static resource container cannot be found


Analyze the cause of the problem:

First, the authority resources are not enough,

Second, static resources are not mounted to the specified root directory in the nginx container

1. Insufficient authority resources

Open the nginx.conf configuration file

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

It is found that the user permission is nginx, change the permission of the nginx.cong configuration file, and change user nginx to user root, permission.

把user nginx更改为 user root

Running the Nginx worker process as the root user can obtain higher privileges and allow more freedom in operating system resources and configuration.

Note: From the perspective of security, it is recommended to use the nginx user to run the Nginx worker process, unless there is a special reason to use the root user.

After changing nginx.conf, you need to refresh the configuration file. It is generally recommended to restart nginx to reload. Sometimes using the nginx configuration file to refresh is invalid

docker stop nginx container ID//pause the container

docker start nginx container ID//Start the container

2. The static resource container cannot be found

Check the default.conf configuration file, the storage location of static resources under the root directory, if there is no problem.

 

It can be that static resources cannot be found inside the container,

You need to use the docker cp command to copy the host static resources to the same directory inside the container

docker cp /opt/dist/ e71be7c28e30:/opt/dist/

Go inside the container to see if the static resource file exists

docker exec -it platformnginx /bin/bash //进入容器内部命令
cd /opt //进入容器内部opt目录下
ls //查看当前目录下文件夹/文件

Static resources already exist, restart nginx, and revisit:

 

 

Guess you like

Origin blog.csdn.net/weixin_56602545/article/details/130411124