【问题标题】:nginx configuration for wordpresswordpress 的 nginx 配置
【发布时间】:2013-12-15 11:56:32
【问题描述】:

我在 /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/”。 感谢您的帮助!

【问题讨论】:

    标签: wordpress nginx


    【解决方案1】:

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

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

    【讨论】:

    • 我试过你的配置,但我得到了2013/12/15 13:34:57 [error] 21982#0: *39 rewrite or internal redirection cycle while internally redirecting to "/index.php/blog/wp-content/themes/twentytwelve/style.css", 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://www.domain.com/"。所以我在 /index.php 和 $request_uri 之间添加了一个空格。现在css/js已经加载成功,但是wordpress的显示还是没有样式,当我点击一个链接时,页面就被下载了。
    • 为什么要通过 index.php 访问 css?不应该是/blog/wp-content/themes/twentytwelve/style.css 没有index.php
    • 是的,但我不知道为什么。
    猜你喜欢
    • 1970-01-01
    • 2022-06-23
    • 2021-08-14
    • 2016-11-03
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 2019-12-02
    • 2022-01-09
    相关资源
    最近更新 更多