【问题标题】:Running Wordpress/NGINX from different path从不同的路径运行 Wordpress/NGINX
【发布时间】:2020-07-09 12:43:55
【问题描述】:

我正在学习 NGINX,因此非常感谢任何帮助。

我有一个网站的前端作为 mysite.com 的根运行,现在我想从 mysite.com/blog 运行 wordpress。

我的文件结构是: /srv/mysite/前端 /srv/mysite/wordpress

这是我从 nginx 日志中得到的错误

2020/03/29 00:09:03 [error] 23049#23049: *39 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: XXXXXXX, server: www.mysite.com, request: "GET /api HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "mysite.com"

这是我目前的 nginx 配置文件

    listen 80 default_server;
    server_name www.mysite.com mysite.com;
    charset utf-8;

    location ^~ /blog {
        root /srv/mysite/wordpress;
    }

   location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    }

    location / {
        root /srv/mysite/frontend/dist;
        try_files $uri /index.html;
    }

}

【问题讨论】:

    标签: php wordpress nginx


    【解决方案1】:

    此错误消息显示 sock 文件的错误路径或权限。确保路径/run/php/php7.2-fpm.sock中存在php sock文件并更改文件的权限。

    For Debian
    
    chown -R  wwww-data:www-data /run/php/php7.2-fpm.sock
    
    For Rhel
    
    chown -R nginx:nginx /run/php/php7.2-fpm.sock
    

    另外,你可以试试这个配置。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 2022-10-25
      • 2020-10-26
      • 2016-12-23
      • 2015-07-15
      • 1970-01-01
      • 2021-12-27
      相关资源
      最近更新 更多