Installing Magento 2.0.2 on Nginx setup page not functioning - php

Need some help installing Magento 2.0.2 on nginx 1.9.3 with php-fpm currently I'm using the default configuration provided by Magento ( https://github.com/magento/magento2/blob/develop/nginx.conf.sample ).
The issue that's happening is when accessing /setup after unpacking it I'm presented with a 403 on "setup/index.php/navigation" as well as other URLs the page attempts to access.
I've realized the issue behind this is that it's not passing "navigation" as an argument to the index.php file and is actually looking for "index.php/navigation" as a file and attempting to pass that to php5-fpm which results in security.limit_extensions to be triggered causing the 403.
So the question becomes how do I get requests to process properly?
E.X. when the javascript being rendered by the setup index.php requests index.php/navigation how do I ensure it's passed to index.php as an argument instead of trying to look for a file at "index.php/navigation" as if index.php were a directory.

This problem become more and more common as I can see. It seems that fastcgi_split_path_info needs to define. Try to changed nginx.conf.sample /setup location block (I pointed to solution-code with ##) to:
location /setup {
root $MAGE_ROOT;
location ~ ^/setup/index.php {
### This fixes the problem:
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
################################
fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/setup/(?!pub/). {
deny all;
}
location ~ ^/setup/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}}

Related

Nginx conf to invoke xslt script to generate php AND process with php-fpm in one request?

Consider the following non-working nginx.conf fragment:
server {
...
root /var/www/html/example.com/www;
location /dev/ {
root /var/www/html/example.com;
location ~* \.(pdf|js|css|png|jpg|jpeg|gif|ico)$ {
}
fastcgi_split_path_info ^/dev/(.+)()$;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html/example.com/xsltproc.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_pass php-fpm;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(x)$;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm;
}
}
location / {
index index.html;
location ~ \.php$ {
...
The objective is to use XSLT to transform .xml into .php and instantaneously serve the generated .php file from the protected /dev/ location all in one step for a fast and easy edit / view cycle.
The xsltproc.php script looks up the resource by $fastcgi_script_name and checks to see if the corresponding .xml or .xsl files are newer than the .php file and, if yes, regenerates it using XSLTProcessor::transformToXML().
When development is complete, the .php files are copied to the www location where they are served in the typical non-xslt manner.
However, the above does not work because, even though location /dev/ matches, location ~ \.php$ is ultimately favored and used such that the .php file is not regenerated. If I temporarily remove the location ~ \.php$ section, the .php file is generated correctly. When the section is restored, the .php file is processed correctly.
How do I configure nginx to invoke xsltproc.php AND process the .php file with php-fpm in the same request?
Meaning I effectively want to invoke php-fpm twice in one request: once for xstlproc.php and once on the generated .php file.
Can an internal redirect be used even though the name of the resource is exactly the same (e.g. /dev/test.php)?
UPDATE:
I have not found a way to invoke php-fpm twice. Adding a rewrite immediately after the xsltproc.php fastcgi_pass call results in a jump for the rewrite without executing the script. No surprise there.
However, I did settle on a solution which was to add:
require($phpfile)
to the end of xsltproc.php to simply include the php file regardless of weather or not it was re-generated and then remove location ~ \.php$. The more I think about it, this is a satisfactory solution. It's only for dev anyway.

NGINX server configuration

I am trying to configure nginx and have the following configuration in:
/etc/nginx/sites-enabled/default
server {
server_name firstproj.dev www.firstproj.dev;
root /var/www/firstProj/web;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
where both app.php and app_dev.php are files in /var/www/firstProj/web/ folder created by symfony with no further modifications.
firstProj is a symfony project that I am currently working on and what I fail to understand here is:
Why when i access www.firstproj.dev I get
Oops! An Error Occurred The server returned a "500 Internal Server Error".
Why when I access www.firstproj.dev/app_dev.php everything is ok and I can also access my routes (eg: www.firstproj.dev/app_dev.php/homepage works perfectly fine and returns the expected response from the action in my controller)
Why when I access www.firstproj.dev/app.php I get 404 error.
I want it to work with www.firstproj.dev/homepage with no app_dev.php there but I cannot make it work that way.
Furthermore, if I access
http://localhost
I get:
Welcome to nginx!
If you see this page, the nginx web server is successfully installed
and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
I apologize if this is a rather dumb question but I'm a beginner as far server configuration is concerned.
Thank you!
So you're finding that your app_dev.php works but app.php does not work?
I've had this happen in the past and there are a few things worth checking.
Copy the contents of app_dev.php into app.php and see if www.firstproj.dev/app.php or www.firstproj.dev work. If it works then you know it's not a problem with NGINX but instead a problem with your Symfony Setup.
Have you created a cache or logs directory for prod or only for dev? Are they writable by www-data?
Have you checked /var/log/nginx/project_error.log to see if any error is showing up when trying to access app.php?
At the top of the app.php file add in the line error_reporting(E_ALL);. Now when you try to access the production version do you see any error?
Try clearing the cache for production. Depending how you have you server setup (Are you using ACL or CHOWN/CHMOD for your cache/log files?) You can run something like sudo su -u www-data php bin/console cache:clear --env prod

nginx serving some PHP URLs as downloads instead of executing

Some PHP URLs are being downloaded instead of executed by Nginx. I have an existing web application which is functioning fine. I'm tasked with adding additional mounted applications within folders of the primary application. Each of these applications has its own front controller index.php script.
For this setup, I've created symlinks inside $document_root/app, and the symlinks point to a folder containing an index.php front controller.
When I navigate to most URLs, everything works fine, the primary application front controller is executed, and I get expected results. When I navigate to a non-existent app, I get 404 Not Found from nginx, which is expected. But when I navigate to one of the applications, the browser downloads the application front controller.
root /my/web/root;
location / {
try_files $uri
/$server_name$uri
/shared$uri
/index.php$is_args$args;
}
location ~ [^/]\.php(/|$) {
disable_symlinks off;
fastcgi_split_path_info ^(.+\.php\b)(.*)$;
fastcgi_param SERVER_NAME $host;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_pass php-fpm;
}
location ~ ^/app/([a-z-]+)(/.*)?$ {
try_files $uri
/app/$1/index.php$is_args$args
=404;
}
URL which triggers download: /app/my-app/ (exists)
URL which 404s: /app/foo/ (does not exist)
URL which executes: /foo
The .php file needs to be processed by the location ~ [^/]\.php(/|$) block. You have a common document root which makes things simpler.
However, look at this document regarding the location directive.
You will see that the regex locations are considered in order and the first matching location will be used to process the request.
In short, you need to place the location ~ [^/]\.php(/|$) block before any other conflicting regex location, if you want your .php files to be processed correctly.

Starting wordpress on nginx debian server

I'm stuck with the installation of Wordpress for Nginx on Debian. The website pointing to my server is mes-affaires.xyz.
Nginx logs are showing 200 responses for any URL from that domain, and appearing all blanks in my browser. That's the difficulty as I'm having no error log of any kind.
Any idea why it's doing this or where I could get a kind of error log?
Now www.mes-affaires.xyz shows nginx default page.
Be sure u got config for your site, and u added it in nginx.conf.
If you are using php-fpm, then you need right setting at server directive. For example:
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
Especially line
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
must have right configuration and causes white blank page in browser when its missconfigured. Also check
$document_root
variable and ofcourse your log files.

Nginx Symfony2 Staging Config

i'm trying to configure nginx to serve several releases of one symfony project.
Releasefolder structure:
/var/www/my-project/releases/24/
/var/www/my-project/releases/46/
/var/www/my-project/releases/47/
I'd like to call a URL like "http://my-server/my-project/release/47" which should access /var/www/my-project/releases/47/web/app.php on the server.
I tried for a while now but couldn't find the final solution, any help would be great!
My last try:
server {
server_name my-server;
location / {
# try to serve file directly, fallback to app.php
try_files $uri $uri$2app.php$is_args$args;
}
location ~ /my-project/release/([-a-zA-Z0-9]+)/app\.php(/|$) {
root /var/www/my-project/releases/$1/web;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/app.php;
fastcgi_param HTTPS off;
error_log /var/log/nginx/my-project_$1_error.log;
access_log /var/log/nginx/my-project_$1_access.log;
# 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;
}
}
This config produces following error:
[error] 2272#0: *169 rewrite or internal redirection cycle while internally redirecting to "/my-project/release/47app.phpapp.phpapp.phpapp.phpapp.phpapp.phpapp.phpapp.phpapp.phpapp.phpapp.php"
You are missing a root directive in your server container -- is /var/www the default on your architecture? Otherwise, add a root directive:
root /var/www;
try_files is failing for find a match and will rewrite the URL by appending app.php to it. The resulting URL does not match your other location block, so it gets rewritten again and again.
The final term on your try_files directive is wrong. You have $2 where /web/ should be (probably inherited from a previous experiment).
Using try_files to make a general rewrite is a bad idea, as any mistyped URL could lead to a rewrite loop. Try:
location / {
rewrite ^(/my-project/release/[-a-zA-Z0-9]+)$ $1/app.php;
}
I changed the config to this:
server {
server_name my-server;
root /var/www;
location / {
rewrite ^(/my-project/release/[-a-zA-Z0-9]+)$ $1/app.php;
}
location ~ /my-project/release/([-a-zA-Z0-9]+)/app\.php(/|$) {
alias /var/www/my-project/releases/$1/web;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/app.php;
fastcgi_param HTTPS off;
error_log /var/www/my-project/releases/$1/app/logs/nginx_error.log;
access_log /var/www/my-project/releases/$1/app/logs/nginx_access.log;
# 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;
}
}
Now a call like "http://my-server/my-project/release/47" points correctly to "/var/www/my-project/releases/47/web/app.php".
The problem is now that the url "my-project/release/47" arrives at symfony router which can't find a route to this url.
What is now the right way to keep the url showing up like "//my-server/my-project/release/47" at browser but arrives at symfony as "//my-server/"?
Thank you all for your help, unfortunately i couln't get it working. I think i have to learn more about nginx configuration generally to be able to handle such problems, before i can use it in production.
My workaround for my problem is to create an own nginx conf per release. The file will be created at build process, is then transfered to the webserver, copied to /etc/nginx/conf.d/[releasename].conf and activated by sudo service nginx reload.
A deinstallation script within the release dir removes sources and config, when release no longer needed.

Categories