我有一个 AWS Ubuntu 服务器,它托管在 127.0.0.1:4100 运行的 React 前端,并使用端口 127.0.0.1:1323 对 Go 应用程序进行 api 调用。我在配置文件中安装了 Nginx 并为这两个端口设置了代理通行证/etc/nginx/sites-available/default,但我只得到 Nginx 调用的前端。使用 chrome 检查检查 Go 应用程序为何不提供 React 应用程序的某些功能,我看到此错误
client.js:772 GET http://127.0.0.1:1323/api/ net::ERR_CONNECTION_REFUSED ERROR 错误:请求已终止 可能原因:网络离线、Access-Control-Allow-Origin 不允许 Origin、页面正在卸载等。
我究竟做错了什么?下面是我的默认配置文件
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
proxy_pass http://127.0.0.1:4100;
}
location /api {
proxy_pass http://127.0.0.1:1323/;
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试在 nginx 中使用流或邮件指令时遇到问题。我正在使用 nginx/1.16.1 和 Ubuntu 18.04.4 LTS。
这是我的 nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1200;
# 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; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log off;
#/var/log/nginx/access.log;
error_log /var/log/nginx/error_website.log; …Run Code Online (Sandbox Code Playgroud) 我使用 nginx 在 Ubuntu 服务器上设置了一个 laravel 项目,现在我需要在同一服务器上部署第二个项目,如果我没有域名但有 IP 地址,我必须如何为我的第二个项目定义 server_name ?我尝试使用XX.XX.XX.XX/mysecondproject但在重新加载 nginx 时出现错误。如果您能帮我解决这个问题,我真的很感激。这是我的 nginx 文件。
server {
listen 80;
listen [::]:80;
root /var/www/mysecondproject/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name XX.XX.XX.XX/mysecondproject;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)
}
我有一项返回的服务:
WWW-Authenticate: Negotiate, Basic realm="TM1"
Run Code Online (Sandbox Code Playgroud)
由于这不适用于 libcurl,我尝试使用 nginx 来修改这些标头,如下所示:
WWW-Authenticate: Negotiate
WWW-Authenticate: Basic realm="TM1"
Run Code Online (Sandbox Code Playgroud)
我失败的尝试#1:
http {
proxy_intercept_errors on;
server {
listen 10103;
server_name localhost;
location / {
proxy_pass https://tm1server:10103;
proxy_intercept_errors on;
proxy_hide_header WWW-Authenticate;
add_header "Status is" "${status}" always;
if ($status = 401) {
add_header WWW-Authenticate 'Basic realm="TM1"' always;
add_header WWW-Authenticate 'Negotiate' always;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
测试:
$ curl -sv http://localhost:10103/api/v1/Configuration
* Trying 127.0.0.1:10103...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 10103 (#0)
> GET …Run Code Online (Sandbox Code Playgroud) 我正在尝试对内部 docker 容器进行 api 调用,但对于每个请求 url,我都必须在 Nginx 配置中创建 proxy_pass。我读过一些文章,最后的斜杠应该可以将某些 url 之后的所有内容传递到 proxy_pass。
www.example.com/api -> 重定向到正确的端点
www.example.com/api/2020 -> 这不会重定向到 http://api/2020
location = /api/ {
proxy_pass http://api/;
}
Run Code Online (Sandbox Code Playgroud)
那么为什么这个配置不将 2020“参数”传递到 api 端点呢?当我进行如下配置时它会起作用:
location = /api/2020 {
proxy_pass http://api/2020;
}
Run Code Online (Sandbox Code Playgroud)
但问题是它是一个参数,所以它可能是任何数字,如何解决这个问题?
我读过其他帖子,但我再次问这个问题,以便更广泛地了解参数传递的可能性。真的有必要为此使用正则表达式吗?
我有一个从 github 项目继承的 nginx.conf 配置文件,我希望有人能解释一下我在做什么:
upstream hello_django {
server web:8000;
}
server {
listen 80;
server_name react-wagtail-api.accordbox.com;
location / {
proxy_pass http://hello_django;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
client_max_body_size 20M;
}
location /static/ {
alias /app/static/;
}
location /media/ {
alias /app/media/;
}
}
server {
listen 80;
server_name react-wagtail.accordbox.com;
location / {
root /usr/share/nginx/html/build;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
和
upstream hello_django {
server web:8000;
}
Run Code Online (Sandbox Code Playgroud)
是web一个服务(其他地方有一个 docker-compose 容器名称,它是web......它是对此的引用吗?)?具体定义是什么 …
我正在使用 nginx 在同一域上提供登录页面、SPA(Ember)和 Rails 后端。一切似乎都运行良好,除非我刷新了一些 SPA 路由,例如https://server_name.ru/app/login NGINX 返回 404 错误
/home/aborovkov/apps/frontend/dist/login" failed。如何解决这个问题?
server {
root /home/aborovkov/apps/landing;
index index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ /index.html?/$request_uri;
add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0";
add_header Pragma "no-cache";
server_name server_name.ru www.server_name.ru;
access_log /etc/nginx/server_name.access.log;
error_log /etc/nginx/server_name.error.log;
location /app {
alias /home/aborovkov/apps/frontend/dist;
index index.html index.htm index.nginx-debian.html
try_files $uri $uri/ /index.html?/$request_uri;
add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0";
add_header Pragma "no-cache";
}
location /api/ {
root /home/aborovkov/apps/api/current/public;
proxy_pass http://localhost:3000;
passenger_enabled on;
passenger_app_env production;
client_max_body_size 100m;
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加一个标头“X-Body”并将其设置为 nginx conf 中请求的响应正文。
pid logs/nginx.pid.test;
error_log logs/error.log.test debug;
worker_rlimit_core 500M;
worker_processes 1;
master_process off;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/json;
sendfile on;
keepalive_timeout 65;
variables_hash_max_size 2048;
server {
listen 65311;
server_name test;
access_log logs/test;
location / {
echo "Nginx response";
proxy_pass_request_headers on;
default_type application/json;
echo_read_request_body;
add_header X-Body $request_body;
return 200;
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下 curl 请求需要标头 X-Body。但是找不到。
curl -vk "localhost:65311" -d '{"key":"value"}' -H "Content-Type: application/json"
* Rebuilt URL to: localhost:65311/
* Trying ::1...
* …Run Code Online (Sandbox Code Playgroud) 我在数字海洋中有一个服务器滴,两个域指向该服务器 A.com 和 B.com 。我希望当 A.Com 被调用时,nginx 将其重定向到 B.com 并作为 B.com 服务器。例如,如果用户从浏览器 B.com 中点击 url,则应显示我的网站,但如果点击 A.com,则应打开同一网站,但域更改为 B.com
我有一个问题,我正在 [主机名]/product/console 上部署一个应用程序,但是从 [主机名]/product/static 请求 .css .js 文件,因此它们没有被加载,我得到 404。
我已经尝试过nginx.ingress.kubernetes.io/rewrite-target:但没有成功。
我也尝试使用:nginx.ingress.kubernetes.io/location-snippet: |
location = /product/console/ {
proxy_pass http://[hostname]/product/static/;
}
但后者似乎根本没有被 nginx 控制器接收到。这是我的 ingress.yaml
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-resource
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/enable-rewrite-log: "true"
# nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/location-snippet: |
location = /product/console/ {
proxy_pass http://[hostname]/product/static/;
}
spec:
rules:
- host: {{.Values.HOSTNAME}}
http:
paths:
- path: /product/console
backend:
serviceName: product-svc
servicePort: prod ##25022
- path: /product/
backend:
serviceName: product-svc
servicePort: prod #25022
Run Code Online (Sandbox Code Playgroud)
-- 可以请教一下吗?我一直在尝试用谷歌搜索并尝试一些不同的变体,但我似乎做错了一些事情。谢谢!
nginx kubernetes kubernetes-ingress nginx-config nginx-ingress
nginx ×10
nginx-config ×10
amazon-ec2 ×1
docker ×1
ember.js ×1
endpoint ×1
kubernetes ×1
laravel ×1
nginx-module ×1