Having issues with Ubuntu 16 and Nginx with the Friendly URLs.

Kane Hart

Active member
So Here is my current config:
/etc/nginx/sites-available$ sudo nano domain.com

Code:
server {
    root /home/websites/domain.com/public_html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name domain.com;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Now I went ahead and attempted to add this into it:
https://xenforo.com/help/friendly-urls/

Without luck I instead had redirect issues, etc. So I'm wondering if someone has something I can try? Strange thing is I'm trying move my forum from server a to server b. I tried copying nginx exactly but I know I was doing silly hackish things before so I thought a fresh start would be best anyways.

Thanks.

PS: The current stuff works great above besides the friendly URL's so I wanted use that as a baseline to try to get /forum/ for example working. Thanks.
 
Code:
server {
   root /home/websites/domain.com/public_html;
   index index.php index.html index.htm index.nginx-debian.html;
   server_name domain.com;

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

   location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       try_files $uri =404;
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
   }

   location ~ /\.ht {
       deny all;
   }

    location /install/data/ {
       internal;
    }
    location /install/templates/ {
       internal;
    }
    location /internal_data/ {
       internal;
    }
    location /library/ {
       internal;
    }

}
 
Thanks mate. Sadly your php area gave me some sort of error:
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

I used xenforo one instead in the first post on their page but I'm getting the 502 bad gateway error including using your stuff minus php one and if I remove the php one of course /forum does not exist.

So it seems all my issues are all around the php area oddly enough.

I tried using my old forums one as well:
Code:
        location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$uri&$args;
        }

And these worked on the old server and instead on this server it downloads a file lol:
Code:
<?php

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$fc = new XenForo_FrontController(new XenForo_Dependencies_Public());
$fc->run();
 
Your include for snippets/fastcgi-php.conf seems non-standard.
What does snippets/fastcgi-php.conf contain?
Code:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

Thanks mate.
 
Try this?

Code:
server {
   root /home/websites/domain.com/public_html;
   index index.php index.html index.htm index.nginx-debian.html;
   server_name domain.com;

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

    location ~ [^/]\.php(/|$) {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
                return 404;
        }
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        include /etc/nginx/fastcgi_params;
    }

   location ~ /\.ht {
      deny all;
   }

   location /install/data/ {
      internal;
   }
   location /install/templates/ {
      internal;
   }
   location /internal_data/ {
      internal;
   }
   location /library/ {
      internal;
   }

}

Check that you have /etc/nginx/fastcgi_params otherwise change the path to where ever your file is
 
Thanks now my site showing something different just a white page hehe. So I feel like it's getting somewhere I did get white page before when screwing around too but not sure why. I should find a way to have to display errors or more info.

That file seems to exist has this:
Code:
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
 
Did some more testing it seems like php pages are blank white but anything else works thankfully :) If that helps!
 
Add;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

above the SCRIPT_NAME line

??
Now were getting somewhere hehe. So normal domain.com works but /forums/server-site-news.23/ ends up being 500 error.

Here is the log:
Code:
[07-Jul-2017 19:12:13] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful

[07-Jul-2017 19:12:13] NOTICE: fpm is running, pid 9932
[07-Jul-2017 19:12:13] NOTICE: ready to handle connections
[07-Jul-2017 19:12:13] NOTICE: systemd monitor interval set to 10000ms
[07-Jul-2017 19:12:14] NOTICE: Terminating ...
[07-Jul-2017 19:12:14] NOTICE: exiting, bye-bye!
[07-Jul-2017 19:12:14] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful

[07-Jul-2017 19:12:14] NOTICE: fpm is running, pid 10703
[07-Jul-2017 19:12:14] NOTICE: ready to handle connections
[07-Jul-2017 19:12:14] NOTICE: systemd monitor interval set to 10000ms
[07-Jul-2017 19:13:19] NOTICE: Terminating ...
[07-Jul-2017 19:13:19] NOTICE: exiting, bye-bye!
[07-Jul-2017 19:13:19] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful

[07-Jul-2017 19:13:19] NOTICE: fpm is running, pid 10757
[07-Jul-2017 19:13:19] NOTICE: ready to handle connections
[07-Jul-2017 19:13:19] NOTICE: systemd monitor interval set to 10000ms

Thanks mate you been a great help. I hope I have not screwed up some files in the root of my forums that cause this but I don't think we use htaccess and such that was apache so I assume not.
 
/var/log/nginx/ error file contents?
Oh nice I removed it and rebooted it no errors. But then I started surfacing the error pages and got this:

Code:
2017/07/09 04:04:52 [error] 20563#20563: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to XenForo_Application::handleException() must be an instance of Exception, instance of Error given in /home/websites/domain.com/public_html/library/XenForo/Application.php:367
Stack trace:
#0 [internal function]: XenForo_Application::handleException(Object(Error))
#1 {main}
  thrown in /home/websites/domain.com/public_html/library/XenForo/Application.php on line 367" while reading response header from upstream, client: 70.xxx.xxx.xxx, server: domain.com, request: "GET /portal/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "domain.com", referrer: "http://domain.com/forum"
2017/07/09 04:04:53 [error] 20563#20563: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to XenForo_Application::handleException() must be an instance of Exception, instance of Error given in /home/websites/domain.com/public_html/library/XenForo/Application.php:367
Stack trace:
#0 [internal function]: XenForo_Application::handleException(Object(Error))
#1 {main}
  thrown in /home/websites/domain.com/public_html/library/XenForo/Application.php on line 367" while reading response header from upstream, client: 70.xxx.xxx.xxx, server: domain.com, request: "GET /portal/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "domain.com"
2017/07/09 04:04:54 [error] 20563#20563: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to XenForo_Application::handleException() must be an instance of Exception, instance of Error given in /home/websites/domain.com/public_html/library/XenForo/Application.php:367
Stack trace:
#0 [internal function]: XenForo_Application::handleException(Object(Error))
#1 {main}
  thrown in /home/websites/domain.com/public_html/library/XenForo/Application.php on line 367" while reading response header from upstream, client: 70.xxx.xxx.xxx, server: domain.com, request: "GET /portal/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "domain.com"
2017/07/09 04:04:57 [error] 20563#20563: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to XenForo_Application::handleException() must be an instance of Exception, instance of Error given in /home/websites/domain.com/public_html/library/XenForo/Application.php:367
Stack trace:
#0 [internal function]: XenForo_Application::handleException(Object(Error))
#1 {main}
  thrown in /home/websites/domain.com/public_html/library/XenForo/Application.php on line 367" while reading response header from upstream, client: 70.xxx.xxx.xxx, server: domain.com, request: "GET /forums/server-site-news.23/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "domain.com", referrer: "http://domain.com/"
2017/07/09 04:04:58 [error] 20563#20563: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to XenForo_Application::handleException() must be an instance of Exception, instance of Error given in /home/websites/domain.com/public_html/library/XenForo/Application.php:367
Stack trace:
#0 [internal function]: XenForo_Application::handleException(Object(Error))
#1 {main}
  thrown in /home/websites/domain.com/public_html/library/XenForo/Application.php on line 367" while reading response header from upstream, client: 70.xxx.xxx.xxx, server: domain.com, request: "GET /forums/server-site-news.23/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "domain.com"
2017/07/09 04:04:59 [error] 20563#20563: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to XenForo_Application::handleException() must be an instance of Exception, instance of Error given in /home/websites/domain.com/public_html/library/XenForo/Application.php:367
Stack trace:
#0 [internal function]: XenForo_Application::handleException(Object(Error))
#1 {main}
  thrown in /home/websites/domain.com/public_html/library/XenForo/Application.php on line 367" while reading response header from upstream, client: 70.xxx.xxx.xxx, server: domain.com, request: "GET /forums/server-site-news.23/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "domain.com"

Thanks
 
But then I started surfacing the error pages and got this:
Seems to suggest it cannot find your php-fpm.
Do you have a file at /run/php/php7.0-fpm.sock ? Should also have /run/php/php7.0-fpm.pid
Does /etc/php/7.0/fpm/pool.d/www.conf have "listen = /run/php/php7.0-fpm.sock" within? Any file within /etc/php/7.0/fpm/ path overwriting this "listen = " directive?

Any other .php files working? Eg. /admin.php ?
 
Seems to suggest it cannot find your php-fpm.
Do you have a file at /run/php/php7.0-fpm.sock ? Should also have /run/php/php7.0-fpm.pid
Does /etc/php/7.0/fpm/pool.d/www.conf have "listen = /run/php/php7.0-fpm.sock" within? Any file within /etc/php/7.0/fpm/ path overwriting this "listen = " directive?

Any other .php files working? Eg. /admin.php ?
All the PHP Files work just fine just not the friendly URL's.

both php7.0-fpm.pid php7.0-fpm.sock are in the locations as suggested.

Also that config has it:
; Note: This value is mandatory.
listen = /run/php/php7.0-fpm.sock


Admin.php works my test (phpinfo) also works. It all seems to work just sadly not the friendly URL's. I'm going to head to bed now but thanks for all the help. Sadly we so far hit a 360 I'm wondering if I should just install old version of ubuntu or if I did something wrong. I'm pretty sure I installed it right it all worked perfect even the forums of course the friendly URL's were broken and since then I have yet to get them to work.
 
I feel like an IDIOT.....

Upgrade Xenforo first before asking for help. I knew mine was older and did not care at the time. But the issue is php7, etc is new... There might be issues with having old archived forum back from 2004 :(

Lesson learned and I learned a lot in this thread.

Thanks @Mouth
 
Top Bottom