Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php NGINX wordpress 404适用于所有子页面_Php_Wordpress_Nginx_Reverse Proxy_Virtualhost - Fatal编程技术网

Php NGINX wordpress 404适用于所有子页面

Php NGINX wordpress 404适用于所有子页面,php,wordpress,nginx,reverse-proxy,virtualhost,Php,Wordpress,Nginx,Reverse Proxy,Virtualhost,我有两个问题,但我认为它们是相关的。像/wp admin、/blog这样的子目录返回404,因此,permalinks不能像/blog/category1/page.php那样工作 我的设置: 我有一台运行nginx的服务器192.168.1.4。在另一台服务器192.168.1.1上,我有一台使用virtualhosts的apache web服务器,它托管着我的wordpress站点。在没有nginx的情况下,设置可以正常工作,但是当我打开nginx时,我遇到了一些问题 Nginx不能与per

我有两个问题,但我认为它们是相关的。像/wp admin、/blog这样的子目录返回404,因此,permalinks不能像/blog/category1/page.php那样工作

我的设置:

我有一台运行nginx的服务器192.168.1.4。在另一台服务器192.168.1.1上,我有一台使用virtualhosts的apache web服务器,它托管着我的wordpress站点。在没有nginx的情况下,设置可以正常工作,但是当我打开nginx时,我遇到了一些问题

Nginx不能与permalinks一起使用。我使用了默认值,因此现在它类似于:http://www.mywebsite.co.uk/?page_id=90 只要它不在子目录中,它就可以正常工作

子目录中的所有内容都不在根中断中。包括管理页面,或在关闭永久链接之前。它们都指向404,特别是:404找不到nginx/1.4.6 Ubuntu

这是我的配置:

server {
    ... config above ...
   location /wp-admin/ {
       index index.php
       try_files $uri $uri/ /wp-admin/index.php?$args;
       proxy_pass http://192.168.1.1$request_uri; 
       proxy_set_header Host $host; 
    }
}
作为参考,这里是我的永久链接:/blog/%category%/%postname%/

更新

已尝试将此添加到我的配置:

server {
    ... config above ...
   location /wp-admin/ {
       index index.php
       try_files $uri $uri/ /wp-admin/index.php?$args;
       proxy_pass http://192.168.1.1$request_uri; 
       proxy_set_header Host $host; 
    }
}
这会在日志中返回一个错误:

rewrite or internal redirection cycle while internally redirecting to "/wp-admin/index.php", client: xxxxx, server: mydomain.co.uk`

您有一些工作配置。在您的配置中,nginx的目的是将代理服务器反转到Apache服务器。在这种情况下,索引和try_文件不合适。尝试:

server {
    server_name mywebsite.co.uk www.mywebsite.co.uk;
    location / {
        proxy_pass http://192.168.1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
   }
}

您有一些工作配置。在您的配置中,nginx的目的是将代理服务器反转到Apache服务器。在这种情况下,索引和try_文件不合适。尝试:

server {
    server_name mywebsite.co.uk www.mywebsite.co.uk;
    location / {
        proxy_pass http://192.168.1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
   }
}

为什么不想在没有apache的情况下尝试wordpress? 工作配置如下所示:

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

    access_log /var/log/nginx/log;
    error_log /var/log/nginx/error.log;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # SECURITY : Deny all attempts to access PHP Files in the uploads directory
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }

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

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

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

    error_page 404 /404.html;

    location ~ /\. { deny all; }

    location ~* ^.+\.(js|css|swf|xml|txt|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)$ {
        access_log off; 
        log_not_found off; 
        expires 30d;
    }
}

为什么不想在没有apache的情况下尝试wordpress? 工作配置如下所示:

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

    access_log /var/log/nginx/log;
    error_log /var/log/nginx/error.log;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # SECURITY : Deny all attempts to access PHP Files in the uploads directory
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }

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

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

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

    error_page 404 /404.html;

    location ~ /\. { deny all; }

    location ~* ^.+\.(js|css|swf|xml|txt|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)$ {
        access_log off; 
        log_not_found off; 
        expires 30d;
    }
}

也许你可以在这里得到你的答案

也许你可以在这里得到你的答案

我发现在我的案例中,问题是没有启用mod_rewrite。我必须使用apache在服务器上运行一个enmod rewrite,我发现在我的案例中,问题是没有启用mod_rewrite。我必须使用apache在服务器上运行a2enmod rewrite

try_文件的第三条路径假定最终移出,但该路径再次到达该位置。@Deadooshka是的,你可能是对的。但这是许多帖子建议的解决问题的方法。Gindex也会对位置进行内部重定向。try_文件的第三条路径假设最终移出,但这条路径又回到了这个位置。@Deadooshka是的,你可能是对的。但这是许多帖子建议我做的,以解决我所遇到的问题。Gindex也会对位置进行内部重定向。我确信我尝试过这个方法,但它确实有效。。。非常感谢你!我肯定我试过了,但它确实起作用了。。。非常感谢你!