I installed Cachethq to have a status page on a server (LAMP) by following this tutorial but I had to use another port (localhost:8080) because I have other services running.
On another server I use Nginx as a reverse proxy to redirect different server/services.
I succeeded to configure Nginx to access cachethq but all the layout does not appear, so I am looking into the fact that I need to redirect php requests to my install server.
I found here several articles and tested different config without success. In addition I would not want these redirects to impact those of my other servers / services.
I'm quite new to Nginx and Php so thanks a lot for your help.
My Nginx config:
location /redmine {
proxy_pass http://10.160.82.6/redmine;
}
location /MagicInfo {
proxy_pass http://10.160.82.16:7001;
}
location /status {
proxy_pass http://10.160.82.6:8080/index.php;
}
location ~ \.php$ {
fastcgi_pass 10.160.82.6:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Related
I'm trying to setup an nginx reverse proxy, deployed as a networked image in ECS. Behind it is a PHP API, running in a separate php-fpm container listening on port 9000. The nginx docs and examples I can find seem to suggest that it has to be configured with a root path within the server block in the config.
The following is an example (from here) of the nginx config that seems to be commonly used in this scenario:
server {
listen 80;
root /var/www/html/public; # is this really needed if proxying all requests to php?
server_name _;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Looking at it from a performance perspective, when a request comes into an API endpoint such as /api/foobar, in this particular scenario there is no point in nginx trying to check the filesystem for an index file inside this folder, since we know for sure there is no such folder. Ideally it should bypass this unnecessary step and simply proxy the request straight to the other container that's running php-fpm, letting it deal with route matching and 404's if an unexpected route is requested.
So, my question is - given a requirement to only serve API requests via a PHP application with "virtual routes" served up via a single index.php entry point (such as Slim) with no need to serve up any static files from a "root" path - is there a way to configure nginx to just proxy all incoming requests using fastcgi_pass?
Is it possible to run multiple NGINX on a single Dedicated server?
I have a dedicated server with 256gb of ram, and I am running multiple PHP scripts on it but it's getting hangs because of memory used with PHP.
when I check
free -m
it's not even using 1% of memory.
So, I am guessing its has some to do with NGINX.
Can I install multiple NGINX on this server and use them like
5.5.5.5:8080, 5.5.5.5:8081, 5.5.5.5:8082
I have already allocated 20 GB memory to PHP, but still not working Properly.
Reason :- NGINX gives 504 Gateway Time-out
Either PHP or NGINX is misconfigured
You may run multiple instances of nginx on the same server provided that some conditions are met. But this is not the solution you should look for (also this may not solve your problem at all).
I got my Ubuntu / PHP / Nginx server set this way (it actually also runs some Node.js servers in parallel). Here is a configuration example which works fine on a AWS EC2 medium instance (m3).
upstream xxx {
# server unix:/var/run/php5-fpm.sock;
server 127.0.0.1:9000 max_fails=0 fail_timeout=10s weight=1;
ip_hash;
keepalive 512;
}
server {
listen 80;
listen 8080;
listen 443 ssl;
#listen [::]:80 ipv6only=on;
server_name xxx.mydomain.io yyy.mydomain.io;
if ( $http_x_forwarded_proto = 'http' ) {
return 301 https://$server_name$request_uri;
}
root /home/ubuntu/www/xxxroot;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ ^/(status|ping)$ {
access_log off;
allow 127.0.0.1;
#allow 1.2.3.4#your-ip;
#deny all;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass adn;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /xxxroot/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
#fastcgi_param DOCUMENT_ROOT /home/ubuntu/www/xxxroot;
# send bad requests to 404
#fastcgi_intercept_errors on;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Hope it helps,
I think you are running into a timeout. Your PHP-Scripts seams to run to long.
Check following:
max_execution_time in your php.ini
request_terminate_timeout in www.conf of your PHP-FPM configuration
fastcgi_read_timeout in http section or location section of your nginx configuration.
Nginx is designed more to be used as a reverse proxy or load balancer than to control application logic and run php scripts. Running multiple instances of nginx that each execute php isn't really playing to the server application's strengths. As an alternative, I'd recommend using nginx to proxy between one or more apache instances, which are better suited to executing heavy php scripts. http://kbeezie.com/apache-with-nginx/ contains information on getting apache and nginx to play nicely together.
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
Trying to setup Magento2 on my LEMP stack. Was following the instructions here and here (did that after compiling from sources for multiple time since it was hard to fulfill composer requirements for Magento2)
Installed composer
Configured and run php, php-fpm
Did some trivial tests (success)
However, a blank screen is all I get. The nginx configuration
server {
listen 2000;
root /usr/share/nginx/html/magento2;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}
The permission set is to -R 777 (test purpose only), user and group is www-data. Was able to run .php scripts, problem applies to Magento2.
Read also some related issues (without any positive results) :
Nginx configuration with Magento 1.8
ngix and php5-fpm blank page
The above query is incomplete the nginx configuration.
Please use the below link configuration of nginx.
http://gotechnies.com/magento2-lemp-nginx-ubuntu/
I am running a small nginx instance on my raspberry. This is working fine so far. It is using SSL and PHP and is running as expected. Now I plan to forward requests to /photo to my local diskstation using proxy_pass.
The Raspberry IP is 192.168.178.3, the diskstation is 192.168.178.2. Accessing the diskstation directly is fine.
The nginx config:
server {
...
location / {
root /var/www;
}
location /photo {
#rewrite ^ $scheme://$host/;
proxy_pass http://192.168.178.2$uri;
}
location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
try_files $script_name =404;
include fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
fastcgi_read_timeout 3600s;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
Unfortunately, nginx handles all *.php requests, but the requests for php files should be forwarded to the diskstation using the proxy_pass setting.
For example, http://192.168.178.3/photo/scripts/uistrings.php?v=6.2-2858&ln=ger returns a 404 but works as expected when sent directly to the diskstation. For all other files like PNG or CSS the proxy_pass works fine.
How to fix the php file problem?
location ^~ /photo {
....
}
This should work. Read http://nginx.org/r/location for details.