本篇内容介绍了“Nginx常见问题有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
telnet *.*.*.* 80
POST /map/navigation/2011winter/jsn/jsn_20120723_pack/pvf.jsn
HTTP/1.1
Host:*.*.*.* (2个回车)
HTTP/1.1 405 Not Allowed
Server: MapbarServer
Date: Mon, 08 Oct 2012 05:34:53 GMT
Content-Type: text/html
Content-Length: 173
Connection: keep-alive
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h2>405 Not Allowed</h2></center>
<hr><center>MapbarServer</center>
</body>
</html>
经查发现:NGINX不允许向静态文件提交POST方式的请求,否则报405错误
解决办法:
1.在nginx vhosts配置文件中增加如下
error_page 405 =200 @405;
location @405 {
root /mapdata/www/datamobile/;
proxy_method GET;
proxy_pass http://map_tomcat;
}
这个情况主要是用vue采用前后端分离之后前端有在public下有一个单独的index.html
他们所有的页面都存放在这个index.html中.也就是说所有的页面请求都要打到这个文件中
所以如果我们通过传统的URL来请求页面比如登录,/user/login时会报错页面不存在
而我们的项目在部署的时候,将所有WEB和APP的接口都单独新建Module中
所以我们的接口请求,必然要有web或app字样,所以我们通过修改NGINX中的配置文件.
优先匹配带有app或web的URL,将其重置到public/index.php给yaf处理
而其他的都交给public/index.html来处理
server {
listen 80;
server_name otc.coinegg.im;
access_log /home/work/logs/nginx/otc.coinegg.im.access.log main;
error_log /home/work/logs/nginx/otc.coinegg.im.error.log;
root /home/work/www/otc/public;
# 禁止请求git相关的隐藏文件,这个也要放到前面来,只要在location / 前面
location ~ /.git/ {
deny all;
}
# 这个要放到前面了来, 做正则匹配,匹配到URL中含有WEB或APP时按照YAF重定向到index.php中
location [/web/|/app/] {
root /home/work/www/otc/public; # 除非路径不同否则这里不用重新定义root
index index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
}
}
# 这要放到后面来, 即所有的请求全部重定向到index.html中
location / {
root /home/work/www/otc/public; # 除非路径不同否则这里不用重新定义root
index index.html;
try_files $uri $uri/ /index.html;
}
# 这里是FPM用的,保持不变即可
location ~ \.php$ {
index index.php;
fastcgi_pass unix:/tmp/unix/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# make -j2如果报错:objs/Makefile:591: recipe for target 'objs/src/core/ngx_murmurhash.o' failed
# 我在ubuntu18.04下有这个错误
# 在objs/Makefile中将 -Werror 删除,对于warnings忽略
# vim objs/Makefile 找到第三行的CFLAGS = -I/usr/local/luajit/include/luajit-2.0 -pipe -O -W -Wall -Wpointer-arith -Wno-unused -Werror -g -DNDK_SET_VAR
# 删掉-Werrori 即可
“Nginx常见问题有哪些”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/chinaliuhan/blog/3074797