nginx配置代理 , 代理vue前端項目


nginx代理vue項目, nginx的配置文件:

假如訪問52ccn.com 代理到后面的vue項目
vue項目路徑/www/website/red/admin

nginx ssl證書位置在這個文件夾下面/usr/local/nginx/conf/cert/

然后項目中接口請求統一使用/prod-api/

然后通過nginx代理到對應得http://localhost:9032/ 對應得后台服務接口

worker_processes  1;
  events {
              worker_connections  1024;
          }
http {
            include       mime.types;
            default_type  application/octet-stream;
            sendfile        on;
            keepalive_timeout  300;
            client_max_body_size 1000m;

    

        server {
            listen 80;
            server_name 52ccn.com; #需要將domain替換成證書綁定的域名。
            rewrite ^(.*)$ https://$host$1; #將所有HTTP請求通過rewrite指令重定向到HTTPS。
            location / {
                index index.html index.htm;
            }
        }

       server {
        listen      443 ssl;
        #請求域名
        server_name  52ccn.com;
        #證書位置在這個文件夾下面/usr/local/nginx/conf/cert/
        ssl_certificate   /usr/local/nginx/conf/cert/7296768_test.52ccn.com.pem;
        ssl_certificate_key  /usr/local/nginx/conf/cert/7296768_test.52ccn.com.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        #請求域名然后顯示admin下面的前台資源頁面
         location / {
            root   /www/website/red/admin;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
            proxy_set_header Host $http_host;
        }
        #前台資源接口如果有/prod-api/ 開頭的接口 走下面的代理9032服務器
        location /prod-api/{
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:9032/;


        }
        #前台資源接口如果有/dev-api/ 開頭的接口 走下面的代理9032服務器   
        location /dev-api/{
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:9032/;

            
        }

 
        #前台資源接口如果有/ysy-api/ 開頭的接口 走下面的https://open.ys7.com/服務器 
        location /ysy-api/ {
            proxy_pass https://open.ys7.com/;
        }
        #前台資源接口如果有/mino-api/ 開頭的接口 走下面的代理9032服務器 
        location /mino-api/ {
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:9000/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    }	
}

HTTP訪問自動跳轉到HTTPS頁面

server {
    listen 80;
    server_name 52ccn.com; #需要將domain替換成證書綁定的域名。
    rewrite ^(.*)$ https://$host$1; #將所有HTTP請求通過rewrite指令重定向到HTTPS。
    location / {
        index index.html index.htm;
    }
}

這樣訪問52ccn.com 就自動跳https://52ccn.com 上了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM