spirog

HI, I thought this might come in handy for anyone looking to use Short URL's with Nginx on PLesk Control Panel

( this is only for someone wanting to run FPM application served by Nginx )

my setup is CentOS 7 with PLesk Obsidian Control Panel

in PLesk there is setting to add additional nginx directives, it's located under > Apache & Nginx Settings.

Additional nginx directives
Here you can specify the settings for the nginx reverse proxy server that runs in front of Apache. Your directives will override the server-wide nginx configuration. For example, you may want to change the connection timeout or to pack requests with gzip. Use the same syntax as you use for nginx.conf. For example, if you want to pack all the proxied requests with gzip, add the line: 'gzip_proxied any;'.

Additional nginx directives

I added this rewrite code below and now its working ( I have Snapshots of the settings below also, and where you add the rewrite code for short url's to work with Nginx for phpFox in PLesk control Panel . It's working great with phpFox version 4.7.8 and should be backward compatible to work with version 4.6.0 and up

UPDATE 04/28/2020

the issue is a bug of Plesk, so if you try to add the additional directive below without doing the steps below you will get the error. so follow the steps and you will not get an error :)

 Latest Plesk Obsidian : if trying to add this directive and you receive an error: Unable to add "location /" to additional nginx directives for domain in Plesk: nginx: [emerg] duplicate location "/"

Using Plesk Obsidian :

  • OS: ‪CentOS Linux 7.7.1908 (Core)‬
  • Product: Plesk Obsidian 18.0.26 last updated at April 24, 2020 01:17 PM
  • In order to get this to work without ERRORS 
  • Alternatively disable proxy mode and only nginx will be serving requests on domain: 

  • 1) Log into Plesk;

  • 2) In Domains > example.com > Apache & nginx directives temporary remove additional nginx directive containing location /;

  • 3) Disable Proxy Mode,  Under Nginx Settings de-select the check mark and click Apply;

  • 4) Then Insert the below necessary directive back into Additional nginx directives and click Apply.

 
if (!-e $request_filename){
	rewrite ^(.*)$ /index.php break;
}
location / {
	rewrite ^/file/(.*) /PF.Base/file/$1 last;
	rewrite ^/static/ajax.php /index.php last;
	rewrite ^/themes/default/(.*) /PF.Base/theme/default/$1 last;
	rewrite ^/(static|theme|module)/(.*) /PF.Base/$1/$2 last;
	rewrite ^/(Apps|themes)/(.*) /PF.Site/$1/$2 last;
	try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
	try_files $uri =404;
	fastcgi_split_path_info ^(.+\.php)(/.+)$;
	fastcgi_pass unix:/var/run/php5-fpm.sock;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
}
location /PF.Base/file/log {
	deny all;
	return 404;
}

 

Here are my photos so you can see how the settings look in PLesk - last photo is where I've added the rewrite code and got short URL's working on mysite :)

 

 

 

Capture4.PNGCapture3.PNGCapture2.PNGCapture1.PNGCapture.PNG

Capture1

 

Capture2

 

Capture3

 

 

Capture4

 

Capture


The last Photo is where I added the rewrite code for phpFox to work with Nginx in Plesk

Click Apply and your all Done. 

then go back to AdminCP and click on Short URL's. 

if it says can't read .htaccess file, you need to manually turn on this feature 

FTP to your public_html folder and open the file 
PF.Base / file / settings / server.sett.php

and look for 
$_CONF['core.url_rewrite'] = '2'; 

and replace that with 
$_CONF['core.url_rewrite'] = '1';

By setting this to "1" this will transform your sites URLs from (example's below): 
https://www.yoursite.com/index.php?do=/blog
to 
https://www.yoursite.com/blog

Save and close the file.

You should now have short url's enabled on your site. 

Hope this Helps someone who may require to run phpFox Short URLS with Nginx on Plesk Control Panel

 

Warm Regards,

 

Spiro G

Attachments
Capture4.PNG 252.27 Kb . 104 Views
Capture3.PNG 306.19 Kb . 92 Views
Capture2.PNG 365.65 Kb . 89 Views
Capture1.PNG 300.92 Kb . 139 Views
Capture.PNG 207.09 Kb . 91 Views
Capture.PNG 207.09 Kb . 103 Views
Capture1.PNG 300.92 Kb . 98 Views
Capture2.PNG 365.65 Kb . 81 Views
Capture3.PNG 306.19 Kb . 113 Views
Capture4.PNG 252.27 Kb . 95 Views
Last update on April 28, 2020 by spirog.
JohnJr

Thanks for the info...I am confused though.  Are you saying it was not working at all with the .htaccess before you did this?  Under your PHP settings are you running PHP as FPM application served by Apache or FPM application served by Nginx or Fast CGI application served by Apache?

If your setting is PHP as FPM application served by Apache then I am confused why my short URL already works for this using htaccess file.

You seem to know way more than I on server stuff so what is the advantage of what your doing besides get short URLs to work.  It looks like I have the same setup as you as I just upgrade to Plesk Obsidian Control Panel as well.

Be the first person to like this.
spirog

Hi @JohnJr , I will update my post: I am running FPM application served by Nginx

so this is only for someone wanting to run FPM application served by Nginx

Notice Proxy Mode has no check mark I turned apache off to run FPM application served by Nginx

Sorry for the confusion :grin:

 

Spiro

Last update on October 29, 2019 by spirog.
spirog

@JohnJr I hope you and your Family are doing well during these crazy times.. 

wishing you and everyone All the Health and Saftey in the world !!!! :)

spirog

If you're looking to gain a bit more performance out of your NGINX web server,  you can do this with the help of gzip compression.

 

NGINX is an outstanding, open source web server. However, as with any server software, there are always ways to seek out as much performance as possible. One such performance route admins will take is that of the gzip compression available with NGINX.

With the help of compression, the server will be sending smaller objects to clients, thereby the pages will be faster to load. One of the big mistakes with compression is betting the whole farm and compressing every object available for each page.

Unfortunately, with this option comes a bit of a trade off. Compressing every object can take significant CPU resources from your server hardware. That, in turn, will cause a slowdown in NGINX, thus rendering the configuration null. 

Simply do this instead.

Instead of compressing every object, configure NGINX to only compress large files and avoid the temptation to compress smaller files (such as images, executables, etc.).

To Accomplish this follow below:

add this below under the additional directive

gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

Once you've added the options, click Apply and then OK

Here's an explanation for the configuration, line by line:

  • gzip on; - enables gzip compression
  • gzip_vary on: - tells proxies to cache both gzipped and regular versions of a resource
  • gzip_min_length 1024; - informs NGINX to not compress anything smaller than the defined size
  • gzip_proxied - compress data even for clients that are connecting via proxies (here we're enabling compression if: a response header includes the "expired", "no-cache", "no-store", "private", and "Authorization" parameters)
  • gzip_types - enables the types of files that can be compressed
  • gzip_disable "MSIE [1-6]\."; - disable compression for Internet Explorer versions 1-6

 

 

Be the first person to like this.