服务器上的nginx 部署多个前端vue项目(不同端口)

部署nginx可参考:https://blog.csdn.net/qq_59716333/article/details/121590065?spm=1001.2014.3001.5501

当需要部署多个前端项目时,/usr/local/nginx/conf/nginx.conf的配置如下

其中示例为两个项目 test2和vueadmin 效果为

http://****:8080

http://****:8081

利用两个server使用两个端口进行部署

 
#user  nobody;
worker_processes  1;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    include otherconf/*.conf;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    #access_log  logs/access.log  main;
 
    server {
               listen       8080;
        server_name  localhost;
 
        location / {
            root /root/nginxproject/test2/;
           index  index.html;
        }
        add_header Access-Control-Allow-Origin "*";
        default_type 'text/html';
        charset utf-8;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
               root html;
        }
    }
  server {
               listen       8081;
        server_name  localhost;
 
        location / {
            root /root/nginxproject/vueadmin/;
           index  index.html;
        }
        add_header Access-Control-Allow-Origin "*";
        default_type 'text/html';
        charset utf-8;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
               root html;
        }
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

你可能感兴趣的:(nginx,vue.js,前端)