Situation: I can acccess the http://10.32.19.107:8080/success page using Spring Boot, and I wrote a default.conf for Nginx like this:
location /test/ {
proxy_pass http://10.32.19.107:8080/success;
}
Then I restart the Nginx container which is in docker. I entered http://10.32.19.107/test but got a 404.
Here is my whole Nginx default.conf:
server {
listen 80;
server_name 10.32.19.107;
# 首页
index index.html;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /test/ {
proxy_pass http://10.32.19.107:8080/success;
}
location /api/ {
auth_request /auth;
proxy_pass http://10.32.19.107:8080/success;
}
location = /auth {
internal;
set $query '';
if ($request_uri ~* "[^?]+?(.*)$") {
set $query $1;
}
proxy_pass http://10.32.19.107:8080/verify?$query;
proxy_pass_request_body off;
proxy_set_header Content-Type "";
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Task: I want to access the same page as http://10.32.19.107:8080/success when I entered http://10.32.19.107/test.
Action: I deleted the Nginx container and map the conf, html, logs, ssl, nginx.conf, conf.d, default.conf to the same file/directory in Nginx and reinstall the container. Here is my command:
sudo docker run --name Nginx -p 80:80
-v /home/jpdeng/projects/openai-microservice/dev-ops/nginx/logs:/var/log/nginx
-v /home/jpdeng/projects/openai-microservice/dev-ops/nginx/html:/usr/share/nginx/html
-v /home/jpdeng/projects/openai-microservice/dev-ops/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v /home/jpdeng/projects/openai-microservice/dev-ops/nginx/conf/conf.d:/etc/nginx/conf.d
-v /home/jpdeng/projects/openai-microservice/dev-ops/nginx/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf
-v /home/jpdeng/projects/openai-microservice/dev-ops/nginx/ssl:/etc/nginx/ssl/ --privileged=true -d --restart=always nginx
Result: still 404 and I don’t know why.
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;
}
2
Answers
HAHA! I FIXED THE PROBLEM! It's because the configuration of the firewall. Just use the command, and it can work:
Now I am a problem solver! The first problem I solve in StackOverflow!
Try this: