neginx 服务启动、暂定、关闭
linux
启动Nginx命令启动命令:
systemctl start nginx
重启Nginx命令重启命令:
systemctl restart nginx
停止Nginx命令停止命令:
systemctl stop nginx
一类前端neginx 代理遇到的问题
前端配置代理配置
proxy: {
'/api': {
target: 'http://192.168.xx.xx:10010',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
'/pc/': {
// 要代理的地址
target: 'http://192.168.xx.xx:10010/',
changeOrigin: true,
},
'/pointcloud': {
// 要代理的地址
target: 'http://192.168.xx.xx:10010',
changeOrigin: true,
}
}
后端配置
server {
listen 6688;
server_name localhost;
location /api {
proxy_pass http://127.0.0.1:10010/;
proxy_pass_request_headers on;
# 重写URL 去除api
rewrite "^/api/(.*)$" /$1 break;
}
location / {
root /usr/share/nginx/html/pointcloudlabel;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/pointcloudlabel;
}
}
出现的问题
http://192.168.xx.xx:6688/pc/xxx/xxx
http://192.168.xx.xx:6688/pointcloud/xx/xx
出现404 错误
server {
listen 6688;
server_name localhost;
location /api {
proxy_pass http://127.0.0.1:10010/;
proxy_pass_request_headers on;
# 重写URL 去除apis
rewrite "^/api/(.*)$" /$1 break;
}
location /pc/ {
proxy_pass http://127.0.0.1:10010/pc/;
proxy_pass_request_headers on;
}
location /pointcloud {
proxy_pass http://127.0.0.1:10010/pointcloud;
proxy_pass_request_headers on;
}
location / {
root /usr/share/nginx/html/pointcloudlabel;
# proxy_pass http://127.0.0.1:10010/;
# proxy_pass_request_headers on;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/pointcloudlabel;
}
}
出现的问题 代理中请求部分和代理部分重复
http://192.168.xx.xx:6687/api/labelingFileMetadata/xx/xx
server {
listen 4001;
server_name localhost;
location /api/labeling {
proxy_pass http://127.0.0.1:10010/;
proxy_pass_request_headers on;
# 重写URL 去除apis
rewrite "^/api/labeling/(.*)$" /$1 break;
}
}
添加 labelingFileMetadata 代理
server {
listen 4001;
server_name localhost;
location /api/labelingFileMetadata {
proxy_pass http://127.0.0.1:10010/;
proxy_pass_request_headers on;
# 重写URL 去除apis
rewrite "^/api/(.*)$" /$1 break;
}
location /api/labeling {
proxy_pass http://127.0.0.1:10010/;
proxy_pass_request_headers on;
# 重写URL 去除apis
rewrite "^/api/labeling/(.*)$" /$1 break;
}
}