wordpress的nginx配置

时间:2013-12-15 11:56:33

标签: wordpress nginx

我在/ var / www / blog中安装了wordpress。我想通过www.domain.com访问它,所以我创建了一个domain.com Nginx配置文件,其中包含:

server {
    listen 80;

    server_name domain.com www.domain.com;

    root /var/www/blog;
    index index.php index.html index.htm;

    access_log /var/log/nginx/www.domain.com.access.log;
    error_log /var/log/nginx/www.domain.com.error.log;

    location / {
            try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}

但是当我打开www.domain.com时,没有加载css / js文件。在我的error.log中,我得到了:

2013/12/15 12:47:29 [error] 19562#0: *9 open() "/var/www/blog/blog/wp-content/themes/twentytwelve/style.css" failed (2: No such file or directory), client: yy.yy.yy.yy, server: domain.com, request: "GET /blog/wp-content/themes/twentytwelve/style.css?ver=3.8 HTTP/1.1", host: "xx.xx.xx.xx", referrer: "http://xx.xx.xx.xx/"
2013/12/15 12:47:29 [error] 19562#0: *11 open() "/var/www/blog/blog/wp-content/themes/twentytwelve/js/navigation.js" failed (2: No such file or directory), client: yy.yy.yy.yy, server: domain.com, request: "GET /blog/wp-content/themes/twentytwelve/js/navigation.js?ver=1.0 HTTP/1.1", host: "xx.xx.xx.xx", referrer: "http://xx.xx.xx.xx/"

我不明白为什么在链接中添加了“/ blog /”。 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

这是我对配置所做的更改,几乎是正确的

server {
    listen 80;
    server_name domain.com www.domain.com;

    root /var/www/blog;
    index index.php index.html index.htm;

    access_log /var/log/nginx/www.domain.com.access.log;
    error_log /var/log/nginx/www.domain.com.error.log;

    location / {
        try_files $uri $uri/ /index.php$request_uri; #change here
    }

    location ~ \.php$ {
        # removed unnecessary lines.
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}