1、常用的nginx命令cdusr/local/nginx/sbin启动或./nginxnginx-squit优雅的停止nginx,当有连接时,会等待连接请求完成,然后杀死worker进程.nginx-sreload优雅重启并重新加载配置文件nginx.confnginx-sreopen重新打开日志文件,一般用来切日志nginx-v查看版本nginx-t查看nginx配置文件nginx-h查看帮助信息 nginx-V详细版本信息,包括编译参数nginx-cfilename指定配置文件ps-ef|grepnginx查看进程nginx-t-c/etc/nginx/nginx.conf或者nginx-t查看是否修改nginx.conf文件的正确二、nginxdefalut.conf跨域配置worker_processes1;client_max_body_size600m;事件{worker_connections1024;}http{包括mime.types;default_type应用程序/八位字节流;服务器{听9292;服务器名称本地主机;add_headerAccess-Control-Allow-CredAccessentialstrue;add_head-允许来源http://101.200.198.179:8106;add_headerAccess-Control-Allow-Methods'POST,GET,OPTIONS,PUT,DELETE';add_header访问控制trol-Max-Age3600;#返回允许脚本访问的headeradd_headerAccess-Control-Allow-Headers'x-requested-with,content-type,Cache-Control,Pragma,Date,x-timestamp';#允许自定义标头,以逗号分隔,不区分大小写add_headerAccess-Control-Expose-Headers'WWW-Authenticate,Server-Authorization';位置/{根html;#本地文件路径indexindex.htmlindex.htm;#访问索引首页文件try_files$uri$uri//index.html#防止页面刷新404#limit_rate1280k;#限制速度}locationweb1/apis{rewrite^.+apis/?(.*)$/$1break;proxy_passhttp://101.200.198.179:8106;}locationweb2/apis{重写^.+apis/?(.*)$/$1中断;proxy_passhttp://101.200.198.179:8106;}error_page500502503504/50x.html;location=/50x.html{根html;}}}ps:配置文件:安装在/etc/nginx/conf.d/dafalut.conf中的nginx配置文件在loca中可以找到化/{root/root/zg;#本地文件索引的路径index.htmlindex.htm;#访问索引首页的文件}自定义首页路径在https://www.zhihu.com/tardis/sogou/art/641250003.常见问题1.端口被占用解决:2.解决413RequestEntityTooLarge(文件传输限制):修改nginx.conf,在httpnginx-sreload和reload中添加upload_max_filesize=50M解决3.解决静态资源加载失败问题浏览器报错:net::ERR_CONTENT_LENGTH_MISMATCH200(OK)解决方法:1.先切换到指定目录,在终端输入以下命令cd/usr/local/var/run/nginx2.更改权限,输入以下命令sudochmod-R777proxy_temp3.重启nginx,输入sudonginx-srelaod4.配置访问本地目录文件位置/{charsetutf-8;根E:\l\vu3\dist\production;#根目录地址autoindexon;#自动索引index.htmlindex.htm;#访问文件名}5、解决网页刷新404问题。在$uri$uri//index.html位置配置try_files#防止页面刷新404
