项目部署
因为项目中使用到了browserHistory,所以build之后需要部署到服务器上
nginx配置示例:
server
{
listen 666;
server_name 47.92.30.98;
root /home/www/antd-admin/dist;
location /api {
proxy_pass http://localhost:8000/api;
}
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
}
演示地址:http://47.92.30.98:666
可以了,部署到linux的nginx,我用windows下的不用安装的nginx不行, 不知道是因为不安装还是因为没配置 index index.html; try_files $uri $uri/ /index.html;
listen 80; server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://localhost:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
登录的时候还是闪一下就404,我把打包好的dist目录下面的文件直接放到nignx里面的html下面了
@yanghong1105

去掉这个看下root html;
按照楼主说的nginx已经配置好,显示登录页,但是会报错,这怎么解决 XMLHttpRequest cannot load http://localhost:8000/api/v1/userInfo. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. 20login:1 XMLHttpRequest cannot load http://localhost:8000/api/v1/user/login. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
@yanghong1105 src/config.js 里 baseURL改成你的IP和端口
谢谢楼主,已经和后台连起来了,但是在nginx里面打开后样式都是乱的,这是怎么回事
截图看下
调好了,谢谢
为什么我现在已经请求成功了,但是表格里面没有数据
@yanghong1105 截图下,你问的不清楚
远程部署要有服务端才有数据的
@yanghong1105 你先过一下源码吧,巩固一下基础
8000又8000,换个端口
@FatFatFox 我的是mac,昨晚500之后403,发现是权限问题,不过500具体是什么原因忘了
@FatFatFox
#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 666;
server_name localhost;
root /Users/jackple/Documents/projects/antd-admin/dist;
#root html;
#charset koi8-r;
#access_log logs/host.access.log main;
location /api {
proxy_pass http://localhost:3000/api;
}
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# 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;
# }
#}
include servers/*;
}
@FatFatFox 是本机配置的问题
部署到nginx代理中,可以打开登陆界面,但是就是无法登陆。望各位大侠指点。 我的配置如下: 环境:centos 7 baseURL: 'http://192.168.0.157:8080/api/v1', //修改源文件 src/utils/config.js,并把端口改为8080.
包文件: 通过 npm run build 把 antd-admin-master项目build成 dist目录下的所有文件。然后把dist目录下的所有文件,都放到 服务器的 /opt/ngnix/node-source/dist-8080; 目录。
nginx 配置如下: server { listen 666; server_name 192.168.0.157;
#charset koi8-r;
root /opt/ngnix/node-source/dist-8080;
#access_log logs/host.access.log main;
location /api {
proxy_pass http://localhost:8080/api;
}
location / {
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
在浏览器中访问:http://192.168.0.157:666 ,进入登陆界面,输入账号 和密码后如下图:

望各位大侠指点。非常感谢!
应该是请求666才对,改baseurl
config.js里面根据nodeenv判断一下,再修改端口打dev和build就不用手动改了
楼上的大侠,你说的是,我只要在bashURL 把端口改成 666,
然而,在nginx中依然是 proxy_pass http://localhost:8080/api; 是這个意思吗?
对