Nginx“自动.dev”设置将无法正确加载WordPress

时间:2014-04-02 11:39:28

标签: wordpress nginx localhost config

按照本指南(http://blog.evan.pro/how-to-set-up-dynamic-virtual-hosts-for-web-development),我尝试设置localhost / nginx配置,这样我就可以轻松运行环境,而无需为每个环境添加单独的条目(在dnsmasq的帮助下)。 当我运行nginx并通过sitename.dev访问任一站点时,使用WordPress的站点似乎无法运行。我认为nginx配置中缺少一些东西,

worker_processes  1;

error_log  /usr/local/etc/nginx/logs/error.log debug;

events {
    worker_connections  1024;
}

http {
    include             mime.types;
    default_type        application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /usr/local/etc/nginx/logs/access.log  main;

    sendfile            on;

    keepalive_timeout   65;

    index index.html index.php;

    server {
        listen 80;
        server_name .dev;

        # dynamic vhosts for development
        set $basepath "/var/www";

        set $domain $host;
        if ($domain ~ "^(.*)\.dev$") {
            set $domain $1;
        }
        set $rootpath "${domain}";
        if (-d $basepath/$domain/public) {
            set $rootpath "${domain}/public";
        }
        if (-d $basepath/$domain/httpdocs) {
            set $rootpath "${domain}/httpdocs";
        }
        if (-d $basepath/$domain/web) {
            set $rootpath "${domain}/web";
        }
        if (-f $basepath/$domain/index.php) {
            set $rootpath $domain;
        }
        if (-f $basepath/$domain/index.html) {
            set $rootpath $domain;
        }

        root $basepath/$rootpath;

        # enable PHP
        index index.php app.php index.html;
        location / {
            index index.php;
            error_page 404 = @indexphp;
            include   /usr/local/etc/nginx/conf.d/php-fpm;
            try_files $uri $uri/ /index.php?$args;
        }
        location @indexphp {
            rewrite ^(.*)$ /index.php$1;
        }
        location ~ ^(.+\.php)(?:/.+)?$ {
            expires off;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
        }

        # block .ht* access
        location ~ /\.ht {
            deny all;
        }
    }
}

例如,访问mynewproject.dev会给我200 OK但没有加载任何内容。访问没有使用WordPress的someotherproject.dev(但使用像PHP这样的服务器语言),我看到网站正确显示。

1 个答案:

答案 0 :(得分:0)

选择以下

1)如果您在文件夹中使用了wordpress,则必须将其附加到您的set $ basepath" / var / www";

2)发布您的错误日志。