due to the limitation of production environment, only one port can be opened 9988
. Projects written by others also use this port, so different request paths can only be used to distinguish different projects.
my project is separate from front to back. The content packaged on the page is placed in the server directory: / usr/local/m2m/nbMsg/browser/dist
, the port of the java backend is 8989
, and the background interface is uniformly prefixed with / api/v1
.
I want to configure to access http://[host]:9988/nbmsg
, which can return the html static page file under the / usr/local/m2m/nbMsg/browser/dist
directory by default. Then all ajax requests on the page start with / api/v1
and need to be proxied to port 8989
.
here is my configuration. One server is the virtual host of the existing 9988
port, and the other virtual host of the 8999
port is added by me. How should I modify the configuration? Let the requests of http://[host]:9988/nbmsg
be forwarded to the virtual host on the 8999
port?
server {
listen 9988;
root /server/html;
-sharp Add index.php to the list if you are using PHP
index index.html index.htm index.php index.nginx-debian.html;
location / {
index index.html index.htm index.php;
-sharp try_files $uri $uri/ =404;
}
location /business/ {
-sharp root /server/html;
try_files $uri $uri/ /business/public/index.php?$query_string;
}
-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp
-sharp request entrance
-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp
location /nbmsg {
proxy_pass http://127.0.0.1:8999;
proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /server/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
}
}
-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp
-sharp my virtural host
-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp-sharp
server{
listen 8999;
index index.html;
location / {
alias /usr/local/m2m/nbMsg/browser/dist;
}
location /api/v1 {
proxy_pass http://127.0.0.1:8989;
proxy_pass_header Server;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
client_max_body_size 300m;
client_body_buffer_size 256k;
proxy_buffer_size 128k;
proxy_buffers 8 32k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
}
}