2022-07-13

vue 前端,nginx代理发布配置方法

#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"';

    #access_log  logs/access.log  main;

    sendfile        on;

    #tcp_nopush    on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;

server {

#修改要监听的端口

listen 8887;

#修改要绑定的域名或IP地址

server_name localhost;

# charset koi8-r;

#access_log  logs/logs.access.log  main;

# vue项目配置

location / {

root /home/owner/vue;

index index.html;

# 避免出现404

try_files $uri $uri/ /index.html;

}

# 后端接口

# 正式环境对应前端打包运行命令 npm run build:prod

location /prod-api/ {

proxy_pass  http://localhost:8888/;

rewrite ^/prod-api/(.*)$ /$1 break;

# 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

# 打包预发布环境 命令npm run build:stage

location /stage-api/ {

proxy_pass  http://localhost:8888/;

rewrite ^/stage-api/(.*)$ /$1 break;

# 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

# signalR

location ~* ^/msgHub {

proxy_pass  http://localhost:8888;

#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

#启用http长连接支持websocket

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

}

# 文件存储 访问 参数设置访问路径需要设置为 http://域名/外网IP/uploads

location /uploads {

# 设置资源存储路径地址

root /home/website;

# linux下对应 /home/website

autoindex on;

}

# redirect server error pages to the static page /50x.html

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;

    #    }

    #}

}

你可能感兴趣的:(2022-07-13)