Home > Backend Development > PHP Tutorial > nginx关于php的二级域名+子目录问题

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

WBOY
Release: 2016-06-06 20:35:10
Original
1765 people have browsed it

具体环境为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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

回复内容:

具体环境为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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

在你的 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>
Copy after login

huandu已经解答了

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template