lushuncheng il y a 5 ans
Parent
commit
3b546ca081
2 fichiers modifiés avec 136 ajouts et 1 suppressions
  1. 64 1
      config/nginx/template/proginn.nginx.conf
  2. 72 0
      config/nginx/template/proxy.nginx.conf

+ 64 - 1
config/nginx/template/proginn.nginx.conf

@@ -4,7 +4,8 @@ server {
     server_name {{domain}}.test-jishuin.proginn.com;
     root /code/web/phphub/public;
     index index.php;
-    
+    rewrite ^/u/(\d+)$ /user/$1 last;
+    rewrite ^/c/([a-z0-9]+)$ /user/collect_article/$1 last;
     location / {
         if (!-e $request_filename) {
             rewrite  ^(.*)$  /index.php?s=$1  last;
@@ -68,6 +69,68 @@ server {
     }
     access_log /data/log/jishuin.log proginn-logid;
 }
+# 解决方案
+server {
+    listen 80;
+    server_name {{domain}}.test-kaifain.proginn.com;
+    root /code/web/;
+    index index.php;
+    rewrite ^/s/([a-z0-9]+)$ /kaifain/s/$1 last;
+    rewrite ^/d/([a-z0-9]+)$ /kaifain/case/$1 last;
+    rewrite ^/c/([a-z0-9]+)$ /kaifain/$1 last;
+    location / {
+        if (!-e $request_filename) {
+            rewrite  ^(.*)$  /index.php?s=$1  last;
+            break;
+        }
+    }
+    set $temp_request_id $http_x_request_id;
+    if ($temp_request_id = "") {
+        set $temp_request_id $request_id;
+    }
+
+    location ~ ^/(composer.json|composer.lock|ThinkPHP/|vendor/|src/|bin/|App/|.git) {
+        deny all;
+    }
+    location ^~ /user/ {
+        proxy_pass http://127.0.0.1:3000;
+        proxy_set_header Host {{domain}}.test.proginn.com;
+    }
+    location ^~ /user/quit {
+        proxy_pass http://127.0.0.1;
+        proxy_set_header Host {{domain}}.test.proginn.com;
+    }
+
+    location ^~ /file/proxyUpload {
+        proxy_pass http://127.0.0.1;
+        proxy_set_header Host {{domain}}.test.proginn.com;
+    }
+
+    location /ajax/getmessage {
+        proxy_pass http://127.0.0.1;
+        proxy_set_header Host {{domain}}.test.proginn.com;
+    }
+    location /api {
+        proxy_pass http://127.0.0.1;
+        proxy_set_header Host {{domain}}.test.proginn.com;
+    }
+    location ^~ /.nuxt {
+        proxy_pass http://127.0.0.1:3000;
+        proxy_set_header Host {{domain}}.test.proginn.com;
+    }
+    location ^~ /_nuxt {
+        proxy_pass http://127.0.0.1:3000;
+        proxy_set_header Host {{domain}}.test.proginn.com;
+    }
+
+    location ~ \.php$ {
+        fastcgi_pass unix:/var/run/php7-fpm.sock;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $request_filename;
+    }
+    access_log /data/log/kafain.log proginn-logid;
+}
 
 server {
     listen 80;

+ 72 - 0
config/nginx/template/proxy.nginx.conf

@@ -221,6 +221,78 @@ server {
         }
     }
 }
+# web service provider
+server {
+    listen 80;
+    server_name {{domain}}.test-kaifain.proginn.com;
+
+    set $temp_request_id $http_x_request_id;
+    if ($temp_request_id = "") {
+        set $temp_request_id $request_id;
+    }
+    set $temp_scheme $http_x_forwarded_proto;
+    if ($temp_scheme = "") {
+        set $temp_scheme $scheme;
+    }
+    set $temp_addr $http_x_forwarded_for;
+    if ($temp_addr = "") {
+        set $temp_addr $remote_addr;
+    }
+    add_header 'X-Request-Id' "$temp_request_id";
+    access_log /data/log/kaifain-access.log proginn-logid;
+
+    if ($http_user_agent ~* (SemrushBot|python|MJ12bot|AhrefsBot|AhrefsBot|hubspot|opensiteexplorer|leiki|webmeup|DotBot|Baiduspider|spider)) {
+        return 444;
+    }
+    if ($http_referer ~* (lottery|shishissc)) {
+        return 444;
+    }
+    location / {
+        limit_req zone=byip burst=100;
+        proxy_pass http://{{ip}}/;
+        proxy_set_header Host $http_host;
+        proxy_set_header X-Real-IP  $temp_addr;
+        proxy_set_header X-Forwarded-For $temp_addr;
+        proxy_set_header X-Forwarded-Proto $temp_scheme;
+        proxy_set_header X-Scheme $temp_scheme;
+        proxy_set_header Origin $http_origin;
+        proxy_set_header X-Request-Id $temp_request_id;
+        proxy_http_version 1.1;
+
+        #=========================CORS nginx配置=============================
+        if ($http_origin ~* (https?://([0-9a-z\-_]+)\.(test|test-rooter|test-jishuin|test-kaifain|test-festival)\.proginn\.com(:[0-9]+)?)$) {
+            set $cors "true";
+        }
+        if ($request_method = 'OPTIONS') {
+            set $cors "${cors}options";
+        }
+        if ($request_method = 'GET') {
+            set $cors "${cors}get";
+        }
+        if ($request_method = 'POST') {
+            set $cors "${cors}post";
+        }
+        if ($cors = "trueget") {
+            add_header 'Access-Control-Allow-Origin' "$http_origin";
+            add_header 'Access-Control-Allow-Credentials' 'true';
+        }
+        if ($cors = "truepost") {
+            add_header 'Access-Control-Allow-Origin' "$http_origin";
+            add_header 'Access-Control-Allow-Credentials' 'true';
+        }
+        if ($cors = "trueoptions") {
+            add_header 'Access-Control-Allow-Origin' "$http_origin";
+            # add_header 'Access-Control-Allow-Origin' '*';
+            add_header 'Access-Control-Allow-Credentials' 'true';
+            add_header 'Access-Control-Max-Age' 1728000;
+            add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since,X-CSRF-TOKEN,Cookie,x-xsrf-token,X-Request-Id';
+            add_header 'Content-Length' 0;
+            add_header 'Content-Type' 'text/plain charset=UTF-8';
+            # return 204;
+            return 200;
+        }
+    }
+}
 # web festival
 server {
     listen 80;