![用于生产角度应用程序的 Docker 和 Nginx 代理](https://linux22.com/image/778130/%E7%94%A8%E4%BA%8E%E7%94%9F%E4%BA%A7%E8%A7%92%E5%BA%A6%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%9A%84%20Docker%20%E5%92%8C%20Nginx%20%E4%BB%A3%E7%90%86.png)
我正在开发一个应用程序,其中调用第三方 API。我在本地和生产中的 API 如下所示
1. http://localhost:8090/rest/api/2/search?jql=search_query
2. http://10.168.8.59:8090/rest/api/2/search?jql=search_query
现在在我的系统中localhost
它运行正常。我创建了一个proxy.conf.json
来绕过 CORS 错误,它如下所示:
代理.conf.json
{
"/rest/*": {
"target": "https://subdomain.mydomin.com/",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
不幸的是,当我尝试在服务器上部署生产时,它给了我404 Not Found error
。
我正在使用docker,这是我的Docker文件好像
FROM node:latest AS builder
WORKDIR /app
COPY . .
RUN npm i && npm run prod_build
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY --from=builder /app/dist/.
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
我运行以下 2 个命令来构建和运行 docker 容器。
docker build -t p_admin --build-arg http_proxy=http://proxysubdom.proxydom.com:8080 --build-arg https_proxy=http://proxysubdom.proxydom.com:8080 .
docker run --env http_proxy=http://proxysubdom.proxydom.com:8080 --env https_proxy=http://proxysubdom.proxydom.com:8080 --rm -d -p 8090:80 p_admin
我找了一些解决方案,但到现在为止都没有用。大多数都说要配置nginx.conf
。这是默认的nginx.conf
。
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
到目前为止,我编辑了nginx.conf
以下内容
server {
listen 80;
server_name 10.168.8.59;
location /rest {
proxy_pass http://10.168.8.59:8090/rest;
}
}
仍然没有结果,我不知道上面写的是否正确。第一次使用 Nginx 和 docker。所有给出的解决方案都让我更加困惑。我该怎么办?