nginx+tomcat配置域名,域名访问tomcat项目
tomcat配置文件不用改,可以默认端口8080
nginx配置文件需要改如下:加反向代理
server
{
listen 80;
server_name mall.tianxiabox.com;#访问tomcat服务的域名
#access_log logs/host.access.log main;
location / {
proxy_pass http://127.0.0.1:8080;#tomcat服务的地址
root html;
index index.html index.htm;
client_max_body_size 20M;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_set_header Host mall.tianxiabox.com;
proxy_set_header X-Forwarded-For "$http_x_forwarded_for, $remote_addr";
}
location ~ .*\.(jpg|png|jpeg|js|css)$ {
proxy_pass http://127.0.0.1:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
以上这样nginx反向代理即可实现使用mall.tianxiabox/项目
域名形式访问项目
VUE访问阿里云服务器nginx,打包成静态文件后不能405,method not allow的问题解决:
比如阿里云端口:46.45.123.113
vue代码运行起来访问这个公网端口没问题,然后打包成静态文件后就不能访问了,解决办法配置nginx代理:
server {
listen 80; # 监听端口
server_name mobile.tianxiabox.com; # 站点域名
index index.html index.htm ; # 默认导航页
location /api/{ #vue端使用mobile.tianxiabox.com/api/接口名来访问服务端接口
rewrite ^.+api/?(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://127.0.0.1:8099; #服务端用的springboot,端口8099
}
location /mallapi/{ #vue端使用mobile.tianxiabox.com/mallapi/接口名来访问服务别的项目端接口
rewrite ^.+mallapi/?(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://127.0.0.1:8089;
}
location / { #vue端静态代码路径
root /home/wwwroot/userbox/dist;
try_files $uri $uri /index.html;
index index.html index.htm;
}
access_log /home/wwwlogs/box-access.log;
}