>백엔드 개발 >PHP 튜토리얼 >nginx关于php的二级域名+子目录问题

nginx关于php的二级域名+子目录问题

WBOY
WBOY원래의
2016-06-06 20:35:101765검색

具体环境为nginx+php,欲配置phpmyadmin。

现在的问题是访问主机域名,html目录下php可以正常运行。但是访问phpmyadmin.xxxxx.com域名,html/phpmyadmin下文件会通过浏览器下载。各种搜索改参数无果,求支援。


具体nginx.conf参数如下:

<code>    server {
        listen       80;
        server_name  localhost;
    root html;

        access_log  logs/host.access.log main;

        location / {
        }

        #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   html;
        }

    location ~ \.php?$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }


        location ~ /\.ht {
            deny  all;
        }
    }
include vhost/*.conf;
</code>

vhosh/*.conf配置如下

<code>server {
        listen       80;
        server_name  phpmyadmin.xxxxx.com;
        root   html/phpmyadmin;
        #charset koi8-r;

        access_log  logs/phpmyadmin.access.log  main;
        #error_log  log/phpmyadmin.error.log main;


        location / {
            index  index.html index.htm index.php;
        }

}
</code>

回复内容:

具体环境为nginx+php,欲配置phpmyadmin。

现在的问题是访问主机域名,html目录下php可以正常运行。但是访问phpmyadmin.xxxxx.com域名,html/phpmyadmin下文件会通过浏览器下载。各种搜索改参数无果,求支援。


具体nginx.conf参数如下:

<code>    server {
        listen       80;
        server_name  localhost;
    root html;

        access_log  logs/host.access.log main;

        location / {
        }

        #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   html;
        }

    location ~ \.php?$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }


        location ~ /\.ht {
            deny  all;
        }
    }
include vhost/*.conf;
</code>

vhosh/*.conf配置如下

<code>server {
        listen       80;
        server_name  phpmyadmin.xxxxx.com;
        root   html/phpmyadmin;
        #charset koi8-r;

        access_log  logs/phpmyadmin.access.log  main;
        #error_log  log/phpmyadmin.error.log main;


        location / {
            index  index.html index.htm index.php;
        }

}
</code>

在你的 phpmyadmin.xxxxx.com 的 vhost 里缺少 fastcgi 的配置,当然不对啦。把你在 localhost 的 vhost 里配置的内容复制过来就差不多对了。

就是以下这些:

<code>error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}

location ~ \.php?$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}
</code>

huandu已经解答了

你没有配置php解析部分,所谓nginx不知道你要通过什么方式去解析

话说你用的lnmp.org的安装包,不太需要自己修改配置文件吧,顶多加个include *.conf用来解析urlwrite

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.