操作起来很简单
首先是在nginx目录下建立两个存放前端文件的地方,当然有一个是自带的html
其次就是重要的conf的配置文件了
可以参考下这里的
user root;
worker_processes auto;events {worker_connections 1024;
}http {log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';types_hash_max_size 2048; # 增大哈希表大小 types_hash_bucket_size 128; # 调整桶大小 include /etc/nginx/mime.types;default_type application/octet-stream;client_max_body_size 1024m;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.# include /etc/nginx/conf.d/*.conf;upstream gateway{server 1.1.1.1:4000;}server {listen 80;server_name 2.2.2.2.8;root /www/nginx/https;index index.html;keepalive_timeout 70;server_tokens off;proxy_set_header x-forwarded-for $remote_addr;location / {root /data/bws/fileplatform/;index index.html;try_files $uri $uri/ /index.html;}location /fileplatform/ {alias /data/bws/fileplatform/;index index.html;try_files $uri $uri/ /index.html;}location /user/ {proxy_pass http://gateway;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /lx-file/ {proxy_pass http://gateway/lx-file/;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /lx-auth/ {proxy_pass http://gateway/lx-auth/;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}server {listen 8080;server_name 2.2.2.2.8;#charset koi8-r;#access_log logs/host.access.log main;
location /dcscloud/composite/httpfile {proxy_pass http://3.3.3.3:4000/dcscloud/composite/httpfile;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /dcscloud/view {proxy_pass http://3.3.3.3:4000/dcscloud/view;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /dcscloud/templates {proxy_pass http://3.3.3.3:4000/dcscloud/templates;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location ~ ^/dcscloud/(?!composite/httpfile|view|templates) { deny all; }location /dcscloud { deny all; }location / {root html;index index.html index.htm;try_files $uri $uri/ /index.html;}
location /user {proxy_pass http://gateway;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /prod-api {proxy_pass http://2.2.2.2.8:18080;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /lx-file {proxy_pass http://gateway;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /dcscloud/ {proxy_pass http://3.3.3.3:4000/dcscloud/;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /fileplatform/ {proxy_pass http://1.1.1.1:80/fileplatform/;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
}
重点就是两个server,并且他们监听的端口不同;
过程中也遇到过很多问题,比如前端文件找不到,该怎么办,那就看打包问题吧
结合日志,以及浏览器的响应,以及接口的响应结果
希望大家没有遇到问题,稳定拿下!