Nginx 基于linux 实现前后端分离,端口反向代理
一、Nginx 安装
首先安装 gcc c++
1.安装gcc:
yum install gcc gcc-c++
2.安装pcre:
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make
make install
3.安装zlib库
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make make install
4.安装openssl:
tar -zxvf openssl-1.0.1t.tar.gz
5.安装nginx:
tar -zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure
make
make install
二、配置前端静态文件及端口代理
修改conf/nginx.conf
1 server { 2 listen 82;#端口号 3 server_name localhost;#本机 4 5 charset utf-8; 6 #access_log logs/host.access.log main; 7 8 location ~ .*\.(gif|jpg|jpeg|png)$ { 9 expires 24h; 10 root /usr/share/devenv/project/ksd-guangfu/;#指定图片存放路径 11 access_log /usr/local/nginx/logs/images.log;#日志存放路径 12 proxy_store on; 13 proxy_store_access user:rw group:rw all:rw; 14 proxy_temp_path /usr/share/devenv/project/ksd-guangfu/;#图片访问路径 15 proxy_redirect off; 16 proxy_set_header Host 127.0.0.1:82; 17 client_max_body_size 10m; 18 client_body_buffer_size 1280k; 19 proxy_connect_timeout 900; 20 proxy_send_timeout 900; 21 proxy_read_timeout 900; 22 proxy_buffer_size 40k; 23 proxy_buffers 40 320k; 24 proxy_busy_buffers_size 640k; 25 proxy_temp_file_write_size 640k; 26 if ( !-e $request_filename) 27 { 28 proxy_pass http://127.0.0.1:82;#默认80端口 29 } 30 } 31 32 location / { 33 root /usr/share/devenv/project/ksd-guangfu/; #html访问路径 34 index index.html index2.htm; #html文件名称 35 36 } 37 38 error_page 404 /404.html; 39 40 # autoindex on; 41 # index index.html index.htm index.shtml; 42 add_header Access-Control-Allow-Origin *; 43 add_header Access-Control-Allow-Headers X-Requested-With; 44 add_header Access-Control-Allow-Methods GET,POST,OPTIONS; 45 location /kstar_api { 46 rewrite ^.+kstar_api/?(.*)$ /$1 break; 47 include uwsgi_params; 48 proxy_pass http://ip:8080; #代理地址 --服务器接口域名 这里写你的后端服务ip+端口 49 50 } 51 }