Symfony-docs: Add webserver configuration for Plesk

Created on 23 Sep 2015  路  10Comments  路  Source: symfony/symfony-docs

Waiting feedback

Most helpful comment

Reason:
You are not able to override the location / directive of nginx on a default Plesk environment.

Workaround:

  1. Enable nginx (instead of Apache).
  2. Enable 'Smart static files processing'
  3. Enable 'Serve static files directly by nginx'.
  4. Use the following additional nginx configuration.

For production:

if (!-f $request_filename) {
    rewrite ^/(.*)$ /app.php last;
}

For development:

if (!-f $request_filename) {
    rewrite ^/app_dev.php(.*)$ /app_dev.php last;
    rewrite ^/(.*)$ /app.php last;
}

Works fine with Plesk 12.5 (and hopefully in the future). It should work for earlier Plesk versions which provide support for nginx.

All 10 comments

I am not in favor in adding more information here (I also think that Plesk is not the right tool to manage your server, but you should use the command line instead). Though let's see what others think about this.

@JHGitty Do you have some explanations (other references) why these changes are necessary?

If the only change needed is about the location, I'm :+1: to add these lines commented:

# uncomment these lines if you can't override the "/" location (e.g. when using Plesk)
# if (!-f $request_filename){
#     rewrite ^/(.*)$ /app.php last;
# }

Reason:
You are not able to override the location / directive of nginx on a default Plesk environment.

Workaround:

  1. Enable nginx (instead of Apache).
  2. Enable 'Smart static files processing'
  3. Enable 'Serve static files directly by nginx'.
  4. Use the following additional nginx configuration.

For production:

if (!-f $request_filename) {
    rewrite ^/(.*)$ /app.php last;
}

For development:

if (!-f $request_filename) {
    rewrite ^/app_dev.php(.*)$ /app_dev.php last;
    rewrite ^/(.*)$ /app.php last;
}

Works fine with Plesk 12.5 (and hopefully in the future). It should work for earlier Plesk versions which provide support for nginx.

There is an official request to the Plesk developers to fix this issue. But this may take a while.

I don't think that this issue will be fixed in the next months.

Please vote here to let the official Plesk developers know that we really need an official fix: https://plesk.uservoice.com/forums/184549-feature-suggestions/suggestions/13072257-nginx-remove-location-directive-from-de

Voted!
Simply silly how they thought including a default location / {} was a good idea.
Just wish there was something that worked for node apps like the above solutions.

Can't access '/' with node/express at all...

EDIT:

using location = / {} worked. I read this, which basically lead me to believe it will use the = modifier first if it's present.

Full directive that worked, placed into "Additional Nginx Directives" under the domain's "Apache & nginx Settings" on Plesk 12.5:

location = / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass https://127.0.0.1:3000;
}
location ~ / {

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass https://127.0.0.1:300;

}

Granted, this is for a node app, but it should work anywhere.

@davidwieler The workaround works fine except for the path /. Do you know why?

I disabled the options Smart static files processing and Serve static files directly by nginx and I've used this configuration:

location = / {
    try_files $uri /app.php$is_args$args;
}

location ~ ^/app\.php(/|$) {
    internal;
}

All pages are rendered fine except for /. On this page it will directly let me download the PHP file instead of executing it.

@JGGitty I ended up having to do some rewrites, and adding some stuff to change the way slashes are handled. I'm not sure if this will help you, but here is everything I added into my Plesk settings:

merge_slashes on;

## Make sure everything is forwarded to https://
if ($scheme = http) {
    return 301 https://$server_name$request_uri;
}

## Remove trailing slashes
rewrite ^/(.*)/$ /$1 permanent;

## If the index.html (can be anything) is looked for, redirect to /
rewrite ^(.+)/index.html$ $1 permanent;

location = /index.html {
    internal;
    error_page 404 =301 $scheme://domain.com/;
}
location = / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-MSGABLE 'test';
    proxy_pass https://127.0.0.1:3000;
}
location ~ / {

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass https://127.0.0.1:3000;

}

Could be that it doesn't know what to do with /, I'm still very new to nginx, hopefully this helps you.

Your code does not help me - I still get this issue:
I get a download file response on the / location (download of the PHP file app.php).
All other path - for example /news - works fine.

Possible solution to auto-downloaded php files: [Nginx serves .php files as downloads, instead of executing them(http://stackoverflow.com/questions/25591040/nginx-serves-php-files-as-downloads-instead-of-executing-them)

Let's close this old issue because none of doc maintainers use that server and we cannot validate or review or maintain this change. Besides, it looks like they should first solve the issue reported here: https://plesk.uservoice.com/forums/184549-feature-suggestions/suggestions/13072257-nginx-remove-location-directive-from-de Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javiereguiluz picture javiereguiluz  路  4Comments

steevanb picture steevanb  路  4Comments

javiereguiluz picture javiereguiluz  路  5Comments

dannyvw picture dannyvw  路  3Comments

samjarrett picture samjarrett  路  4Comments