I am running a VPS server with Centos and Plesk.
The server is working right, on a Nginx + php-fpm setup.
So, websites are served correctly, but when user tries to access to its webemail ( roundcube tool installed ), doesn't work.
My current nginx conf for webmail is :
server {
listen [my server ip...]:80;
server_name webmail.* roundcube.webmail.* horde.webmail.* atmail.webmail.*;
client_max_body_size 20m;
client_body_buffer_size 128k;
proxy_read_timeout 90;
location / {
root /usr/share/psa-roundcube;
index index.php index.html index.htm;
location ~ \.php$
{
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include /etc/nginx/fastcgi_params;
fastcgi_keep_conn on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
}
}
}
What can be wrong?
This snippet works for me on CentOS 6.5. The SCRIPT_FILENAME is different and the is fastcgi_index is present. Think that's it.
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
I have copied it from here and it works. The other directives in this particular example are very worth to get noticed/copied to harden the plesk setup just a little.
Related
I am running a NodeJS application in Nginx with a reverse proxy to port 3000
PhpMyAdmin is configured and apparently runs in /phpmyadmin
/etc/nginx/sites-available/default is configured like this:
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost mywebsite.com www.mywebsite.com;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /phpmyadmin {
root /var/www/html/phpmyadmin/;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
I managed to make all work as I wanted, but PhpMyAdmin has a bad display:
Before setting the reverse proxy in that file, PhpMyAdmin ran perfect. I assume there is something I missed in default file. Any ideas? Thanks
To Ivan Shatsky's Response: #IvanShatsky
I tried substituting with your code, but it downloads a file (it does not read .php files) - So, I added few more lines:
location ^~ /phpmyadmin {
index index.php;
try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
The result is the same before.
When I check the resources of the network, this is what happens:
I have performed chmod 777 -R /var/www/html/phpmyadmin but no changes. Would I need to have https? - I am currently trying on http.
I wonder how it is running at all. Assuming your phpMyAdmin located in the /var/www/html/phpmyadmin directory, try this:
location /phpmyadmin {
index index.php;
try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
}
I am new to symfony. I am trying to setup symfony2 on ubuntu server with nginx. but it shows 500 internal server error. I have this server running some laravel projects as well and its find
Anyone can help what the problem is?
my nginx configuration is :
server {
listen 80;
root /home/ubuntu/test-symfony/web;
index app.php;
# Make site accessible from http://localhost/
server_name symfony.jonesjapriady.com http://symfony.jonesjapriady.com;
error_log /var/log/nginx/symfony2.error.log;
access_log /var/log/nginx/symfony2.access.log;
location / {
try_files $uri /app.php?$query_string;
}
location ~ ^/(app_dev|app_test.php|app)\.php(/|$) {
include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
}
}
When I try to auto_prepend a file in one of my virtualhosts I think it is cached by FastCGI and used on another virtualhost as well. The first code block is one of my sites auto prepending a file:
server {
listen 80;
server_name www.site1.com;
root /var/www/site1;
index index.php;
# use fastcgi for all php files
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "auto_prepend_file=/file.php";
include fastcgi_params;
}
}
The second site does not auto prepend the file but actually does so anyway if site1 is requested in any way before site2. It seems like the "fastcig_param PHP_VALUE" is cached somehow for both sites.
server {
listen 80;
server_name www.site2.com;
root /var/www/site2;
index index.php;
# use fastcgi for all php files
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
i had installe nginx on my local machine,
my problem is i would like to do a cache for my website .
help to configure nginx
this my configuration
server
{
server_name .mywebsite.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
root /var/www/example.com/html;
index index.php index.html index.htm;
# use fastcgi for all php files
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to apache .htaccess files
location ~ /\.ht
{
deny all;
}
}
but i dosen't had any static content on my local machine
help please best regards
I would like to deploy lithium on nginx server, however there are configurations provided only for Apache and IIS.
I've successfully written several nginx server configurations for various applications in past, but I'm struggling with this one.
Already asked this question on nginx and lithium forums, no luck.
This is best of what I've made so far.
root /var/servers/my_app/app/webroot;
location / {
index index.php;
try_files $uri $uri/ index.php;
}
location ~ \.php {
fastcgi_pass unix:/tmp/php.socket;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/servers/my_app/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
Problem is on / (root page) every link gets index.php prepended, e.g. instead of
www.example.com/something
I get
www.example.com/index.php/something
Not sure if this even is nginx configuration related or rather something, that lithium does when it cannot detect Apache/IIS environment. Either way I cannot solve it.
Another thing, that when I access "www.example.com/test" (via direct URL input), the page renders correctly, however "www.example.com/test/" (with trailing slash) and "www.example.com/test/anything_here" is broken - all links gets appended to current URL e.g. pressing the same link creates this:
www.example.com/test/
www.example.com/test/test
www.example.com/test/test/test
EDIT: Updated configuration
(Sorry for much delayed edit, but I'm still stuck and recently restarted solving this)
root /var/server/my_app/app/webroot/;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
location ~ \.php {
fastcgi_pass unix:/tmp/php.socket;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/servers/my_app/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
location ~/\.ht {
deny all;
}
}
As I mentioned in comments this now causes all links to have index.php included, it looks like:
www.example.com/index.php/something
www.example.com/index.php/stylesheet.css
I think your problem is that the try_files shouldn't be inside a location block.
Try the configuration shown here: http://li3.me/docs/manual/configuration/servers/nginx.wiki
I helped define it and have been using it locally and in production. It shouldn't cause any of the issues you're reporting.
Copying it below:
server {
listen IP_ADDRESS_HERE:80;
server_name DOMAIN.COM;
root /var/www/DOMAIN.COM/webroot/;
access_log /var/log/DOMAIN.com/access.log;
error_log /var/log/DOMAIN.com/error.log warn;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
As I suspected the problem was that Lithium relies on some environment variables, in this case - link generation, it uses PHP_SELF, which happened to be incorrect.
Solution:
fastcgi_param PATH_INFO $fastcgi_path_info;
Instead of previously incorrect:
fastcgi_param PATH_INFO $fastcgi_script_name;
So final configuration:
root /var/server/my_app/app/webroot/;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
location ~ \.php {
fastcgi_pass unix:/tmp/php.socket;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/servers/my_app$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~/\.ht {
deny all;
}
Thanks to rmarscher and mehlah # lithum forums.