0

I am trying to step a bit out my comfort zone as programmer and trying to do myself a full setup from a webserver . I could do it using apache, but, I have the need to use proxy_pass because I have a few golang API's . Doing some research I realized I could get better benchmarkers if I also set up a proxy for my Symfony application :

But, to run this symfony app I need to use a subdirectory. So far, I managed to run golang and symfony thru a proxy_pass on ngnix, but, Symfony has not rewrited the routes :

So, when I access http://MYIP/mysubdir/app_dev.php/myroute all the (background) loaded urls ( for files, scripts, ajax requests, etc ) are like http://MYIP/app_dev.php/myroute

And of course, I need the 'mysubdir' on the url !

How do I rewrite the url to solve my problem ???

I am running Ubuntu 18.04 on a vps, php fpm 7.3 and nginx/1.14.0 (Ubuntu)

/etc/nginx/sites-avaliable/default

    server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {

    try_files $uri $uri/ =404;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}

location /mysubdir/ {



    proxy_pass http://127.0.0.1:8080/;
    proxy_cache mysubdir_cache_setup;
    proxy_cache_key "$scheme://$host$request_uri";
    proxy_cache_lock on;
    proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
    add_header X-Cache $upstream_cache_status;

    error_log /var/log/nginx/mysubdir_cache_error.log;
    access_log /var/log/nginx/mysubdir_cache_access.log;
}

location /phpmyadmin {
        index index.php index.html index.htm;
        root /usr/share;
}

location /goapi/ {

        proxy_pass http://127.0.0.1:9003/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cache_bypass $http_upgrade;
 }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one

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

and #/etc/nginx/sites-available/mysubdir

server {


    listen 8080;

    server_name localhost 127.0.0.1;

    root /var/www/html/mysubdir/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
       # When you are using symlinks to link the document root to the
       # current version of your application, you should pass the real
       # application path instead of the path to the symlink to PHP
       # FPM.
       # Otherwise, PHP's OPcache may not properly detect changes to
       # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
       # for more information).
       fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
       fastcgi_param DOCUMENT_ROOT $realpath_root;
       # Prevents URIs that include the front controller. This will 404:
       # http://domain.tld/app.php/some-path
       # Remove the internal directive to allow URIs like this
       internal;
   }

   # return 404 for all other php files not matching the front controller
   # this prevents access to other php files you don't want to be accessible.
   location ~ \.php$ {
     return 404;
   }

   error_log /var/log/nginx/mysubdr_error.log;
   access_log /var/log/nginx/mysubdr_access.log;
}

Sure I have both files properly linked on ../sites-enabled/

phpmydmin and goapi locations are working fine

Please, How can I solve this matter ?!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.