Solution to Nginx docker container version deployment access 403

Article directory

Problem record

  • A 403 problem appears in the nginx.conf log. Since the container version of nginx does not have any editing tools, it is not possible to view the configuration content of the nginx file in the container.
  • It may be a permissions issue. The analysis shows that there is a problem with the proxy request, which is not proxying to the correct remote server. As you can see from the log, the proxy request is not sent to the remote host.
1.194.128.78 - - [04/Dec/2023:11:12:39 +0000] "GET /api/product/getBaseCategoryList HTTP/1.1" 403 
238 "http://47.92.131.235/home" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36 Edg/119.0.0.0"

Solve the result

  • After the editor’s crazy exploration and attempts, the initial configuration file of local nginx was modified. Finally, the normal configuration file content is as follows:
  • Please modify it based on your own project and try it based on this configuration file.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;


include /usr/share/nginx/modules/*.conf;

events {
    
    
    worker_connections 1024;
}

http {
    
    
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

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

    server {
    
    
        listen       80;
        server_name  _;
        # include /etc/nginx/default.d/*.conf;

	    location / {
    
    
		    root   #本地vue项目地址;
            try_files $uri $uri/ /index.html;
            index  index.html;
    	}
	    location /api {
    
    
            proxy_pass 远程主机地址; #http://xxx.xxx.xxx.xxx
	    }
        error_page 404 /404.html;
        location = /404.html {
    
    
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    
    
        }
    }


server {
    
    
        listen       8080;
        server_name  localhost;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

        location / {
    
    
            root   #本地vue项目地址;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
		# 监听的请求location 请根据时机项目内容进行配置
        location /dev-api/ {
    
    
            proxy_pass 远程主机地址; #http://xxx.xxx.xxx.xxx
            proxy_set_header Host $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;  
            rewrite ^/dev-api/(.*)$ /$1 break;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
    
    
            root   html;
        }
    }
}


Guess you like

Origin blog.csdn.net/yang2330648064/article/details/134819814