JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

nginx配置攻略

wys521 2024-09-04 15:40:46 精选教程 79 ℃ 0 评论
#user nobody;
worker_processes 1;
#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;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
  
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root xcrmaster;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8082/;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root xcrmaster;
}

}

}

主要说明

server{} --配置服务的代码块

server {listen 80;--配置前端服务访问的端口

配置首页的转发路径:

location / {

root xcrmaster;#配置nginx目录下对应的路径;这个路径直接把 npm run build:prod 编译生成的目录dist/*下的所有内容放上去即可

try_files $uri $uri/ /index.html;

index index.html index.htm;

}

配置后端请求路径:

proxy_pass http://localhost:8082/;

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表