# Nginx
## 安装
执行如焉命令安装Nginx源。
```
[root@localhost ~] rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
```

使用 yum 命令安装 Ngnix

```
[root@localhost ~] yum install nginx
```

配置开机启动与启动

```
[root@localhost ~] systemctl enable nginx
[root@localhost ~] systemctl start nginx
```

## 配置
### 常用 Nginx 命令
启动nginx

```
[root@localhost ~] nginx
```

测试 Nginx 配置是否正确
```
[root@localhost ~] nginx -t
```

重启 Nginx
```
[root@localhost ~] nginx -s reload
```

### Nginx的默认路径
* Nginx配置路径：/etc/nginx/
* PID目录：/var/run/nginx.pid
* 错误日志：/var/log/nginx/error.log
* 默认访问日志：/var/log/nginx/access.log
* 默认站点目录：/usr/share/nginx/html
* ibms访问日志：/opt/logs/host.access.log

### Nginx 配置

ibms Nginx配置文件

```
server {
    listen       9001;
    server_name  localhost;
		client_max_body_size 1024m;

    #charset koi8-r;

    access_log  /opt/logs/host.access.log; #  main;
	
    root        /opt/nginx/ibms/dist;              #vue项目的打包后的dist

    location / {
        try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
        index  index.html index.htm;
    }
    location @router {
       	rewrite ^.*$ /index.html last;
    }
   	location ^~ /admin/ {
       	proxy_pass              http://192.168.20.236:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    20m;
       	client_body_buffer_size 128k;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   3;
       	proxy_send_timeout      3600;
       	proxy_read_timeout      3600;
		
	rewrite ^/admin/(.+?)$ /$1 break;
    }
    location ^~ /api/ {
        proxy_pass              http://192.168.20.236:8080;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    20m;
        client_body_buffer_size 128k;
        proxy_buffers           32 4k;
        proxy_connect_timeout   3;#nginx服务器与被代理的服务器建立连接的超时时间
        proxy_send_timeout      3600;#nginx服务器想被代理服务器组发出read请求后，等待响应的超时间
        proxy_read_timeout      3600;#nginx服务器想被代理服务器组发出write请求后，等待响应的超时间

	rewrite ^/api/(.+?)$ /$1 break;
    }
		location ^~ /modelapi/ {
        proxy_pass              http://192.168.20.225:8082;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    1024m;
        client_body_buffer_size 128k;
        proxy_buffers           32 4k;
        proxy_connect_timeout   36000;#nginx服务器与被代理的服务器建立连接的超时时间
        proxy_send_timeout      36000;#nginx服务器想被代理服务器组发出read请求后，等待响应的超时间
        proxy_read_timeout      36000;#nginx服务器想被代理服务器组发出write请求后，等待响应的超时间

	rewrite ^/modelapi/(.+?)$ /revit-algorithm/$1 break;
    }
    location ^~ /data-platform-3/ {
       	proxy_pass              http://192.168.20.225:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    20m;
       	client_body_buffer_size 128k;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   3;
       	proxy_send_timeout      3600;
       	proxy_read_timeout      3600;
	rewrite ^/data-platform-3/(.+?)$ /data-platform-3/$1 break;
    }
    location ^~ /business-space/ {
       	proxy_pass              http://192.168.20.225:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    20m;
       	client_body_buffer_size 128k;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   3;
       	proxy_send_timeout      3600;
       	proxy_read_timeout      3600;
		
	rewrite ^/business-space/(.+?)$ /business-space/$1 break;
    }
	location ^~ /pointconfig/ {
       	proxy_pass              http://192.168.20.236:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    20m;
       	client_body_buffer_size 128k;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   3;
       	proxy_send_timeout      3600;
       	proxy_read_timeout      3600;
		
	rewrite ^/pointconfig/(.+?)$ /pointconfig/$1 break;
    }
	location ^~ /venders/ {
       	proxy_pass              http://192.168.20.225:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    20m;
       	client_body_buffer_size 128k;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   3;
       	proxy_send_timeout      3600;
       	proxy_read_timeout      3600;
		
	rewrite ^/venders/(.+?)$ /venders/$1 break;
    }
        location ^~ /venders-dp/ {
        proxy_pass              http://192.168.20.225:8080;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    20m;
        client_body_buffer_size 128k;
        proxy_buffers           32 4k;
        proxy_connect_timeout   3;
        proxy_send_timeout      3600;
        proxy_read_timeout      3600;

        rewrite ^/venders-dp/(.+?)$ /venders-dp/$1 break;
    }
	location ^~ /ScanBuilding/ {
      	proxy_pass              http://192.168.20.236:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    20m;
       	client_body_buffer_size 128k;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   3;
       	proxy_send_timeout      3600;
       	proxy_read_timeout      3600;
		
	rewrite ^/ScanBuilding/(.+?)$ /ScanBuilding/$1 break;
    }
	location ^~ /image-service/ {
       	proxy_pass              http://192.168.20.225:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    1024m;
       	client_body_buffer_size 1m;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   36000;
       	proxy_send_timeout      36000;
       	proxy_read_timeout      36000;
		
	rewrite ^/image-service/(.+?)$ /image-service/$1 break;
    }
	location ^~ /godhand/ {
       	proxy_pass              http://192.168.20.225:8080;
       	proxy_set_header        Host            $host;
       	proxy_set_header        X-Real-IP       $remote_addr;
       	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       	client_max_body_size    20m;
       	client_body_buffer_size 128k;
       	proxy_buffers           32 4k;
       	proxy_connect_timeout   3;
       	proxy_send_timeout      3600;
       	proxy_read_timeout      3600;
		
	rewrite ^/godhand/(.+?)$ /godhand/$1 break;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
```
