基础环境
- 已经安装好nginx环境
- 需要准备好jepaas的静态资源
静态资源列表如下图:(需要将这些资源部署到nginx的部署目录中,本文档参考路径为/data/www/jepaas)
- appPlugin
- error
- plugin
- pro
- static
- index.html
- index_single.html
- login.html
配置nginx的虚拟主机
前提:已经安装好nginx并且把静态资源已经部署到nginx(当前参考目录为/data/www/jepaas),并且后端jepaas已经启动
虚拟主机参考配置如下:
server {
listen 80; #需要配置的端口号
server_name 127.0.0.1; #需要配置的域名
error_page 404 500 login.html;
charset utf-8;
#access_log /var/log/nginx/host.access.log main;
#root /data/je-platform/deploy;
location = / {
root /data/www/jepaas; #静态文件部署的目录
index index.html;
}
location ~ /favicon.ico {
root /data/www/jepaas; #静态文件部署的目录
proxy_connect_timeout 1;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 256k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404 http_504 http_502;
proxy_max_temp_file_size 128m;
}
location ~ .*\.(js|css|ico|png|jpg|eot|svg|ttf|woff|json|html|js|css|ico|png|jpg|gif|eot|svg|ttf|woff|json|txt|ico|mp4|gz) {
root /data/www/jepaas; #静态文件部署的目录
proxy_send_timeout 1000;
proxy_read_timeout 1000;
proxy_buffer_size 256k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
#proxy_next_upstream_tries 1;
proxy_max_temp_file_size 128m;
proxy_cache_valid 200 304 12h;
proxy_cache_valid 301 302 1d;
proxy_cache_valid any 1m;
proxy_cache_key $uri$is_args$args;
expires 30d;
}
location /socket.io/ {
proxy_redirect off;
#proxy_buffers 8 32k;
#proxy_buffer_size 64k;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# proxy_set_header Connection $connection_upgrade;
proxy_request_buffering off;
proxy_buffering off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
#proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:7001/socket.io/; #代理socket, localhost为socket所在服务器ip
}
location /jesocket {
proxy_redirect off;
#proxy_buffers 8 32k;
#proxy_buffer_size 64k;
proxy_pass http://localhost:7000; #代理socket, localhost为jesocket所在服务器ip
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# proxy_set_header Connection $connection_upgrade;
proxy_request_buffering off;
proxy_buffering off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
#proxy_set_header X-NginX-Proxy true;
}
location ^~ /instant {
proxy_pass http://localhost:8088; ##代理instant, localhost为instant所在服务器ip
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
location / {
proxy_pass http://localhost:8080; #代理jepaas, localhost为jepaas主所在服务器ip
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
client_max_body_size 500m;
client_body_buffer_size 256k;
proxy_connect_timeout 1;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
}
}
配置完成后重启nginx,在浏览器上输入对应的域名或者ip进行访问验证
最后编辑: 肖海杰 文档更新时间: 2024-08-21 10:58 作者:肖海杰