欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > 一个nginx实现两个前端?

一个nginx实现两个前端?

2025/3/14 14:07:04 来源:https://blog.csdn.net/qq_58968195/article/details/146235737  浏览:    关键词:一个nginx实现两个前端?

操作起来很简单

首先是在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,并且他们监听的端口不同;

过程中也遇到过很多问题,比如前端文件找不到,该怎么办,那就看打包问题吧

结合日志,以及浏览器的响应,以及接口的响应结果

希望大家没有遇到问题,稳定拿下!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词