nginx 配置

1, 一个域名多个项目

server {
  listen 80;
  listen [::]:80;
  
  server_name xxxxx.cn;
  proxy_intercept_errors on;

  index index.html index.htm;
  # root /raray/wwwroot;
  error_page 404 500 502 503 504 /50x.html;
  
  location /50x.html {
   	root /usr/share/nginx/html;
  }
  
  location /healthz {
    add_header Content-Type "text/plain";
    return 200 "OK";
  }

  location /dspx_meta_api/ {
    client_max_body_size    120m;
    proxy_connect_timeout   150s;
    proxy_send_timeout      5m;
    proxy_read_timeout      5m;
    proxy_temp_file_write_size 1024m;
    proxy_buffer_size         1m;
    proxy_buffers             4 4m;
    proxy_busy_buffers_size 4m;
    proxy_ignore_client_abort on;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Scheme $scheme;
    proxy_pass http://dspx_engine_meta:8080/;
  }

  location / {
    proxy_redirect off;
    proxy_pass http://dmp-ops-web:80/;
    proxy_http_version 1.1;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Nginx-Proxy true;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
  }

  location /remote_addr {
    default_type text/plain;
    return 200 "$remote_addr\n";
  }
}

配置成功的项目


server{
	listen 80 ;
	server_name xxxxxx.cn ;

        location ^~ /kaoshi/ {
            proxy_redirect off;
            proxy_pass     http://localhost:8088/;
            proxy_set_header  Host       $host;
            proxy_set_header  X-Real-IP    $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header X-Nginx-Proxy true;

            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $http_host;
     }
}

302跳转配置

例如:/go-c-47431127487.html?a=1&pt=home&pv=47431127487&mid=22176&cid=47431127487&url=https%3A%2F%2Folivie.cz nginx 配置

server {
    listen 80;    # 监听80端口
    server_name your_domain.com;  # 替换为你的域名

    location /go-c- {
        # 处理所有以 /go-c- 开头的请求
        rewrite ^/go-c-(\d+)\.html$ /newpath/$1.html break;  # 根据需要进行重写
        # 其他配置,可以根据要求进行处理
    }

    location / {
        # 其他配置,例如代理到后端服务
        proxy_pass http://backend_server;
    }

    # 处理静态文件
    location /static/ {
        alias /path/to/static/files/;  # 替换为静态文件的路径
    }
}

302跳转

    location /go-c- {
        # 处理所有以 /go-c- 开头的请求
        rewrite ^/go-c-(\d+)\.html$  https://www.xxxxx.com/go-c-$1.html redirect;# 根据需要进行重写
        # 其他配置,可以根据要求进行处理
    }

前段图片nginx配置

    # 重要:确保包含_nuxt路径的location配置
    location ~* ^/(_nuxt|static|icons|img|gif|public)/ {
        proxy_pass http://localhost:3004; # 确保这与你的Nuxt.js应用服务器相匹配
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
posted @ 2022-10-11 18:31  Lafite-1820  阅读(248)  评论(0编辑  收藏  举报