V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
angelsky11
V2EX  ›  NGINX

nginx 二级目录无法访问

  •  
  •   angelsky11 · 2015-01-06 13:07:05 +08:00 · 9811 次点击
    这是一个创建于 3388 天前的主题,其中的信息可能已经有所发展或是发生改变。
    刚开始接触这个,在自己的vps ubuntu上架了nginx
    然后在nginx的root目录里放了程序的文件夹aaa
    一开始访问 mydomain/aaa 时提示403错误
    修改了权限以后再次访问
    浏览器自动弹出下载框下载index.php文件
    直接访问 mydomain/aaa/index.php 也是直接下载index文件

    求教是不是我的nginx配置文件出了问题

    谢谢
    9 条回复    2015-01-06 19:08:09 +08:00
    vilison
        1
    vilison  
       2015-01-06 13:13:10 +08:00 via iPhone
    配置php的运行环境,nginx反向访问
    angelsky11
        2
    angelsky11  
    OP
       2015-01-06 13:15:31 +08:00
    @vilison 这个不太懂啊,能否说的明白点,谢谢了
    vilison
        3
    vilison  
       2015-01-06 13:17:59 +08:00 via iPhone
    服务器上配了Apache 或者 php-fpm没有?
    tuuuz
        4
    tuuuz  
       2015-01-06 13:52:55 +08:00
    不知道能不能解决你的问题:
    [Nginx目录浏览功能] http://blog.licess.com/nginx-autoindex/
    bingx86
        5
    bingx86  
       2015-01-06 14:28:53 +08:00
    配置后端CGI了木有,如php-fpm ?
    lizhijun
        6
    lizhijun  
       2015-01-06 14:37:22 +08:00
    php解析有问题
    hzqim
        7
    hzqim  
       2015-01-06 15:23:49 +08:00
    nginx 默认只解析静态 html ,如果要解析 PHP ,首先要安装 PHP ,之后在server段添加如下代码

    location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }

    即这个样子:

    server {
    listen 80;
    root your_web_root;
    index index.php index.html index.htm;
    server_name XXX.com;

    location / {
    这里填rewrite lules,如果不需要就留空
    }

    location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }
    }
    angelsky11
        8
    angelsky11  
    OP
       2015-01-06 19:04:08 +08:00
    @hzqim 我按照这两篇文章 http://huoding.com/2013/10/23/290 http://www.cnblogs.com/quinnxu/archive/2013/05/08/3066274.html
    里面参考的修改了一下,但是启动好以后再访问还是不行,还是之前的问题,下载index.php文件
    php5-fpm运行正常
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3439 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:03 · PVG 20:03 · LAX 05:03 · JFK 08:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.