如何在一台服务器上部署多个项目,并且共用一个域名:
1:将nginx部署到linux下的/usr/local文件夹下
2:在nginx/conf文件夹下创建一个文件夹叫Assist,在Assist文件夹下创建配置文件Assist.conf
Assist.conf的配置如下:
server {
listen 80;
server_name 10.106.133.65;
access_log logs/Assist2.access.log main;
error_log logs/Assist2.error.log warn;
root html;
index index.html;
#迭代一的项目
location /Assist/
{
proxy_next_upstream error timeout http_503 http_502 http_504 invalid_header;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 1000m;
client_body_buffer_size 150m;
proxy_ignore_client_abort on;
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
proxy_buffer_size 128m;
proxy_buffers 4 128m;
proxy_busy_buffers_size 128m;
proxy_temp_file_write_size 128m;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
proxy_intercept_errors on;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://Assist_server;
}
#迭代二前端的包
location /dist/
{
proxy_next_upstream error timeout http_503 http_502 http_504 invalid_header;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 1000m;
client_body_buffer_size 150m;
proxy_ignore_client_abort on;
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
proxy_buffer_size 128m;
proxy_buffers 4 128m;
proxy_busy_buffers_size 128m;
proxy_temp_file_write_size 128m;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
proxy_intercept_errors on;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://Assist2_server;
}
#迭代二的项目
location /Assist2/
{
proxy_next_upstream error timeout http_503 http_502 http_504 invalid_header;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 1000m;
client_body_buffer_size 150m;
proxy_ignore_client_abort on;
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
proxy_buffer_size 128m;
proxy_buffers 4 128m;
proxy_busy_buffers_size 128m;
proxy_temp_file_write_size 128m;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
proxy_intercept_errors on;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://Assist2_server;
}
#迭代一的图片保存的位置
location /upload/
{
proxy_next_upstream error timeout http_503 http_502 http_504 invalid_header;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 1000m;
client_body_buffer_size 150m;
proxy_ignore_client_abort on;
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
proxy_buffer_size 128m;
proxy_buffers 4 128m;
proxy_busy_buffers_size 128m;
proxy_temp_file_write_size 128m;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
proxy_intercept_errors on;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://Assist_server;
}
}
3:在conf文件夹下修改nginx.conf的配置如下:
#user nobody;
#worker_processes 2;
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;
charset utf-8;
log_format main '$remote_addr - - [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "-" "$host" "$http_x_forwarded_for" "$upstream_cache_status"'
access_log on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#设置请求缓存
server_names_hash_bucket_size 128;
#连接超时时间,单位是秒
keepalive_timeout 65;
#开启gzip压缩功能
gzip on;
#设置允许压缩的页面最小字节数
gzip_min_length 1k;
#压缩缓冲区的大小,表示申请4个单位为8k的内存作为压缩结果流缓存
gzip_buffers 4 8k;
#压缩版本
gzip_http_version 1.1;
gzip_types text/* text/css application/javascript application/x-javascript;
#设置请求缓存
client_header_buffer_size 16k;
#设置请求缓存
large_client_header_buffers 4 64k;
#隐藏响应header和错误通知中的版本号
server_tokens off;
#设置请求缓存
client_max_body_size 1000m;
proxy_set_header X-Real-IP $proxy_add_x_forwarded_for;
#允许重新定义或者添加发往后端服务器的请求头
proxy_set_header Host $host;
# $server_port 代表nigix监听的端口
# $proxy_port 代表服务器真正访问的端口
#upstream表示负载服务器池
# upstream ivop2_server {
# server 10.162.117.172:18080;
# #server 10.162.117.172:29998;
# }
#
# upstream test_server {
# server 10.162.117.172:18085;
# }
# upstream ivop2dev_server {
# server 10.162.171.14:18080;
# }
# upstream ivop2_c21_server {
# server 10.186.55.146:18888;
# #server 10.162.117.172:29998;
# }
# upstream test_sjj_server {
# server 10.186.75.22:8055;
# #server 10.162.117.172:29998;
# }
upstream Assist_server{
server 10.106.133.65:8080;
}
upstream Assist2_server {
server 10.106.133.65:8090;
}
include Assist/Assist.conf;
#include test/test.conf;
#include ivop2/ivop2dev.conf;
#include ivop2/ivop2.conf;
#include ivop2_c21/ivop2_c21.conf;
#include pachong/pachong.conf;
# include jira/jira.conf;
# server {
# listen 127.0.0.1:88;
# server_name 127.0.0.1:88;
# location /_nginx_status {
# stub_status on;
# access_log off;
# }
# }
}