Nginx:WordPress重写不工作,除非我做坏事

时间:2015-04-24 12:46:52

标签: wordpress nginx url-rewriting

我最近刚从Apache迁移到Nginx,我正在使用Wordpress和Nginx进入砖墙。暂时我正在运行一个更简单的Nginx配置,这样你就可以更容易地看到正在发生的事情,而不必再查看50多条线路。



server {
    listen          80;
    server_name     servername.com
    root            /home/sname/www;

    # IF I DON'T DO THIS ALL PAGES APART FROM THE HOMEPAGE DON'T APPEAR!
    # Further to this, I use a custom permalink structure %post_name%.
    # When turned off the pages work but I can't use custom permalink structure
    error_page 404 /index.php;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }

    # PHP Handler
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}




我拥有HTTP块中的所有常用内容:



http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;

    index   index.php index.html index.htm;

    include /etc/nginx/conf.d/*.conf;




为什么我不能忍受这个?那么这是一个全网站的例子。 (由于URLS和链接限制错误,因此在网站名称中加入了网站)

http://www.pro-tradesouthwales.co.uk/services/damp-proofing/< - 我想要投放的网页 sitename!/ services / damp-proofing< ---不显示404(以下全部显示空白页面) sitename!/services/damp-proofing/index.php< ---不显示404或重定向 sitename!/services/damp-proofing/index.php/< ---好吧这很糟糕!

sitename!/services/damp-proofing/index.php/index.php< --- O GOD!

任何和所有帮助赞赏。我已经尝试了很多不同的设置,并试图让它工作几天。请不要光顾我的东西,比如阅读指南,我吃了该死的nginx字典仍无济于事:)

谢谢你们!

1 个答案:

答案 0 :(得分:1)

让它在某种程度上发挥作用。事实证明WordPress只是有问题,但据我所知,这是设置WordPress网站最“正确”的方式:)

希望它也有助于其他人。请记住,事情会根据您的服务器而改变,并且它是独特的设置。所以你的PHP设置可能会有所不同。例如,php-fpm目录并不总是存在,有时也会创建为php5-fpm。如果有疑问,请使用shell(使用putty或类似的东西通过SSH连接到您的服务器)并找到php-fpm.sock。

AKA: cd / etc / dir -a ----显示文件列表---- ... 等

    server {
        listen       80;
        server_name  www.pro-tradesouthwales.co.uk;
        root         /home/protrade/www;

        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        
        # START: Solution
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        # END: Solution

        location ~ /\. {
                deny all;
        }

        location ~* /(?:uploads|files)/.*\.php$ {
                deny all;
        }

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location ~* \.(js|css|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
                expires max;
                log_not_found off;
        }

        location ~* \.()$ {
               log_not_found off;
               expires max;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
    }