一、nginx常用命令
cd usr/local/nginx/sbin 启动 或者./nginx
nginx -s quit 优雅进行nginx,有连贯时会等连贯申请实现再杀死worker过程
nginx -s reload 优雅重启,并从新载入配置文件nginx.conf
nginx -s reopen 从新关上日志文件,个别用于切割日志
nginx -v 查看版本
nginx -t 查看nginx的配置文件
nginx -h 查看帮忙信息
nginx -V 具体版本信息,包含编译参数
nginx -c filename 指定配置文件
ps -ef|grep nginx 查看过程
nginx -t -c /etc/nginx/nginx.conf 或者 nginx -t 查看对nginx.conf文件的批改是否正确
二、 nginx defalut.conf跨域配置
worker_processes 1;
client_max_body_size 600m;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 9292;
server_name localhost;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Origin http://101.200.198.179:8106;
add_header Access-Control-Allow-Methods 'POST,GET,OPTIONS,PUT,DELETE';
add_header Access-Control-Max-Age 3600;
#容许脚本拜访的返回头
add_header Access-Control-Allow-Headers 'x-requested-with,content-type,Cache-Control,Pragma,Date,x-timestamp';
#容许自定义的头部,以逗号隔开,大小写不敏感
add_header Access-Control-Expose-Headers 'WWW-Authenticate,Server-Authorization';
location / {
root html; # 本地文件的门路
index index.html index.htm; # 拜访index首页的文件
try_files $uri $uri/ /index.html #避免页面刷新404
#limit_rate 1280k; #限度速度
}
location web1/apis {
rewrite ^.+apis/?(.*)$ /$1 break;
proxy_pass http://101.200.198.179:8106;
}
location web2/apis {
rewrite ^.+apis/?(.*)$ /$1 break;
proxy_pass http://101.200.198.179:8106;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
ps:
配置文件:
装的nginx配置文件在/etc/nginx/conf.d/dafalut.conf
可在 location / {
root /root/zg; # 本地文件的门路
index index.html index.htm; # 拜访index首页的文件
}
中自定义首页面路劲
https://www.zhihu.com/tardis/sogou/art/64125000
三、 常见问题
1. 端口被占用解决:
2.解决413 Request Entity Too Large(文件传输限度):
批改nginx.conf
在http中退出
upload_max_filesize = 50M
nginx -s reload 从新加载即可解决
3.解决动态资源加载失败问题
浏览器报错:
net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)
解决:
1. 先切换到指定目录,在终端输出以下命令
cd /usr/local/var/run/nginx
2. 更改下权限,输出以下命令
sudo chmod -R 777 proxy_temp
3. 重启nginx,输出
sudo nginx -s relaod
四、 配置拜访本地目录文件
location / {
charset utf-8;
root E:\l\vu3\dist\production; # 根目录地址
autoindex on; # 主动索引
index index.html index.htm; # 拜访文件名称
}
五、解决刷新网页404问题
location 中配置
try_files $uri $uri/ /index.html #避免页面刷新404
发表回复