1. Nginx安装
https://blog.csdn.net/qq825478739/category_11423046.html
2. Nginx代理服务
修改配置文件 nginx.conf
- server 服务
- listen 端口 这里需要注意 端口号
- location 代理地址
- proxy_set_header 设置请求头参数
- $remote_addr 内置参数 请求地址ip
- set 自定义参数
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
##代理的服务
server {
listen 8080;
server_name javaserver;
#*星号代表任意跨源请求都支持 服务处理跨域请求 nginx就不需要在处理跨域了
#add_header Access-Control-Allow-Origin '*';
#add_header Access-Control-Allow-Credentials "true";
#add_header Access-Control-Allow-Methods 'GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACES';
#add_header Access-Control-Allow-Headers 'x-requested-with,authorization,Content-Type,farm,store';
#if ($request_method = 'OPTIONS') {
# return 200;
#}
# 判断请求头X-Real-IP是否存在 存在不赋值 不存在重新赋值
set $http_url $http_x_real_ip;
if ($http_url = '') {
set $http_url $remote_addr;
}
proxy_set_header X-Real-IP $http_url;
# 代理 跳转地址
location /VideoPlatform {
proxy_pass http://192.168.8.105:8000/VideoPlatform;
}
# 代理 跳转地址
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
}
3. 注意
if
if 后边需要空格
错误的: if(判断)
if(判断){
}
正确的
if (判断){
}
proxy_set_header 不能在if 中