nginx 访问localhost老是下载文件不能打开网页什么情况?
nginx打开网页直接下载文件的问题
nginx sites-available文件里的default已经修改过root 路径了。 但是访问localhost的时候总是直接下载网页而不是打开网址 很奇怪。
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html/laravel/public;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name 127.0.0.1;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
原因
看题主配置里面有laravel,看来是跟php有关,如果是php,那么题主你应该先去下载php5-fpm才对,因为nginx本身不像apache一样会执行php程序,而是交给php5-fpm执行.
所以,题主你的步骤应该如下 :
下载php5-fpm
配置nginx,使nginx跟fpm通信,网上有很多配置方法,我不重复,这里指提醒一点 : nginx跟fpm通信方式有两种,一个是通过ip,一个是通过socket.fpm跟nginx里面要配置成同一种通信方式!!
最后测试是否成功.当然有可能到了这里还会出现访问页面下载下来的情况,如果遇到这个情况就需要再排查了,但是题主先搞定fpm比较稳妥.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
改动的地方不多 :
index我把index.php放在第一位置
root路径,这里注意最后路径不要有
/去掉跟php有关的注释,我在fpm的
/etc/php5/fpm/pool.d/www.conf中找到listen = /var/run/php5-fpm.sock,说明fpm是开启了socket,所以nginx的fastcgi_pass参数也是socket.
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
这串代码我取消注释 nginx restart 会报错
nginx 访问localhost老是下载文件不能打开网页什么情况?的更多相关文章
- 访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案
访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案: 打开客戶端浏览器--工具---internet-安全-自定义级别-选择到低到中低. 然后点受信任站点,把你要访问的站点 ...
- 有哪些api接口可以实现微信自动唤醒浏览器,下载app,打开网页
现在微信渠道可以说是拉新最快的渠道,因为微信具备强裂变性.但是目前微信对第三方下载链接的拦截是越来越严格了,那么想要在微信内肆无忌惮地推广链接就需要用到微信跳转浏览器的接口,那如何获取该接口呢? ...
- nginx配置虚拟路径下载文件(.apk)
公司将安卓apk文件放到服务器上,实现用户点击链接并下载 nginx version 1.14.1 nginx配置修改 server { listen 80; server_name localhos ...
- 在MFC中通过访问IP地址下载文件到本地
void CDownLoad::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 CDialogEx::OnOK(); UpdateData(TRUE); CStri ...
- asp.net将页面内容按需导入Excel,并设置excel样式,下载文件(解决打开格式与扩展名指定的格式不统一的问题)
//请求一个excel类 Microsoft.Office.Interop.Excel.ApplicationClass excel = null; //创建 Workbook对象 Microsoft ...
- Winform中上传、下载文件选择打开文件的位置
打开将要上传的文件 var fileName="";OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Mul ...
- (转nginx不浏览直接下载文件的解决方法
原文:https://www.zhan200.com/xwt/39.html 如果nginx配置不对,就会造成部分文件,在浏览器中不是直接预览,而是进行了下载.修改的方法是修改配置文件.具体解决方法如 ...
- ionic实现下载文件并打开功能(file-transfer和file-opener2插件)
作为一款app,下载文件功能,和打开文件功能,在某些场景下还是十分有必要的.使用cordova-plugin-file-transfer和cordova-plugin-file-opener2这两个插 ...
- 简单修改hosts文件加快打开网页速度
这个电脑小技巧的帖子菲菲博客分享如何通过简单一招利用修改系统的hosts文件来实现有效加快浏览器打开网页的速度.尤其是网络繁忙时DNS服务器负担加重的时候效果特别明显,有兴趣就和菲菲一起来学习一下吧, ...
随机推荐
- hash与map的区别联系应用(转)
一,hashtable原理: 哈希表又名散列表,其主要目的是用于解决数据的快速定位问题.考虑如下一个场景. 一列键值对数据,存储在一个table中,如何通过数据的关键字快速查找相应值呢?不要告诉我一个 ...
- 第六届蓝桥杯C++B组省赛
1.奖券数目 2.星系炸弹 3.三羊献瑞 4.格子中输出 5.九数组分数 6.加法变乘法 7.牌型种数 8.移动距离 9.垒骰子 10.生命之树 1.奖券数目 奖券数目有些人很迷信数字,比如带“4”的 ...
- http基础知识摘录
HTTP是一个基于请求/响应模式的,无状态的协议 (只有客户端发送请求服务器才会响应,否则服务器不会主动发送信息的,无状态指客户端发过来一个请求服务端给你发回一个响应,接着你再去发送一个请求,服务器根 ...
- 如何从kernel源码中查出版本号(转载)
转载:http://m.android.tgbus.com/tgmobile/arc/174624.shtml 目前查版本号的方法都是在编译以后从rootfs里看的,难道从源码就看不到,一定要编译以后 ...
- sourceTree 的使用
一.拉取其他分支代码 1.git clone 代码是下载master分支 2.在未做修改的情况下,合并分支 二.提交代码到其他分支 1.创建分支(名称可以与远程不同) 2.(正常提交步骤)将作出的修改 ...
- Codeforces gym 101061 G【递推公式+逆元】
题意: 就是n复制m次,然后数mod1e9+7; 思路: 案例:31*10^6 + 31*10^4 + 31*10^2 + 31*10^0 所以就是一个等比数列,然后整理一下就是n*(10^(m*le ...
- python 元类 type metaclass
python中一切皆对象,类对象创建实例对象,元类创建类对象,元类创建元类. 元类创建类对象有2中方式: 一.type方法 type(类名, 由父类名称组成的元组(针对继承的情况,可以为空),包含属性 ...
- bzoj 5210: 最大连通子块和【动态dp+树剖+线段树+堆】
参考:https://www.cnblogs.com/CQzhangyu/p/8632904.html 要开longlong的 首先看dp,设f[u]为必选u点的子树内最大联通块,p[u]为不一定选u ...
- 组合数学1.4&3.10 By cellur925
本文引用于清华大学出版社卢开澄.卢华明<组合数学第五版>. 今天我们稍微讨论下圆排列以及$n$对夫妻的问题. 1.4圆周排列 这个问题是:从$n$个人中取$r$个在圆周上,我们用$Q(n, ...
- spring MVC 文件上传错误
1.The request sent by the client was syntactically incorrect () http://luanxiyuan.iteye.com/blog/187 ...