I am relatively new to NGINX, I admit (less than 24 hours), but, I got it basically configured. I'm setting up a site for a friend, and I saw an example of some code that uses subdomains like in the code below. But, in the subdomain, PHP won't work. It just asks me to download the file if I go to "subdomain.domain.tld", but, if I go to "subdomain.domain.tld/index.php", it says "No input file specified." The subdomain is phpmyadmin, by the way.
server {
listen 80;
server_name irc.physibots.info;
rewrite (.*) http://physibots.info:3989;
}
server {
listen 80;
server_name "~^([a-z]+)?.physibots.info";
root /home/virtual/physibots.info/subdomains/$1;
index index.php index.html index.html;
location / {
autoindex on;
}
location ~ \.php {
try_files $uri /error.html
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
include fastcgi_params;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
#server {
# listen 443;
# server_name localhost;
#
# charset utf-8;
#
# ssl on;
# ssl_certificate
server {
listen 80;
server_name physibots.info default;
root /home/virtual/physibots.info/public_html;
index index.php index.html index.html;
location / {
autoindex on;
}
location ~ \.php {
try_files $uri /error.html
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
include fastcgi_params;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Move the try_files to your location / { } block and change it to try_files $uri $uri/ /index.php;
location / {
autoindex on;
try_files $uri $uri/ /index.php;
}
location ~ \.php {
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
The rest looks surprisingly good for a beginner. :)
Also- make sure you're testing with curl and not a web browser or you'll constantly fight caching.
Related
I'm trying to setup nginx to begin working with phalcon, here's the config :
server {
listen 80;
server_name localhost.dev;
set $root_path '/usr/share/nginx/html/phalcon/public';
root $root_path;
index index.php index.html index.htm;
charset utf-8;
rewrite_log on;
location / {
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path/public;
}
location ~ /\.ht {
deny all;
}
}
I tried all possibilites but still I can't get it working.
Any clues?
look here
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
I have a problem with the configuration of nginx. Structure directory in my server is:
/var/www/public_html is my page.
/var/www/pma - phpmyadmin
/var/www/vimbadmin - ViMbAdmin
My /etc/nginx/sites-available/default
server{
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
access_log /var/www/log/access.log;
error_log /var/www/log/error.log;
root /var/www/public_html;
index index.php index.htm;
# Make site accessible from http://localhost/
server_name localhost;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /pma/ {
index index.php;
alias /var/www/phpmyadmin/;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
}
}
location /vma/ {
index index.php;
alias /var/www/vimbadmin/public/;
try_files $uri $uri/ /index.php?$args;
index index.php;
location ~\.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#try_files $uri =404;
include fastcgi_params;
}
}
}
Now when I go: domian.com/vma/ redirect me to domian.com/vma/auth/login and I see:
File not found.
Phpmyadmin works.
I know that the configuration is bad... But where is mistake?
I did something like this
location ~ ^/vma {
alias /usr/local/vimbadmin/public;
location ~ ^/vma/(.*\.(js|css|gif|jpg|png|ico))$ {
alias /usr/local/vimbadmin/public/$1;
}
rewrite ^/vma(.*)$ /vma/index.php last;
location ~ ^/vma(.+\.php)$ {
alias /usr/local/vimbadmin/public$1;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
charset utf8;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT /usr/local/vimbadmin/public;
}
}
it works, at least on my machine ;)
The answer of ir1keren did not work for me with ViMbAdmin V3.0.11.
Here is how I did it:
#
# ViMbAdmin 3.0.x Nginx configuration
# Directory where ViMbAdmin is installed
set $vimbadmin /var/www/vimbadmin;
location /vma {
alias $vimbadmin/public;
index index.php index.html index.htm;
location ~ ^/vma/(.*\.(js|css|gif|jpg|png|ico))$ {
alias $vimbadmin/public/$1;
}
rewrite ^/vma(.*)$ /mail/index.php last;
# Pass PHP scripts to FastCGI server
location ~ \.php$ {
#try_files $uri =404;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_split_path_info ^/vma/(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APPLICATION_ENV production;
fastcgi_index index.php;
fastcgi_pass php-backend;
fastcgi_intercept_errors on;
}
}
I have the following server settings, and for some reason, my document root is going to the wrong location. Why is it doing that? $1 is correct on the return line, but why is it pulling the wrong root?
This block is broken:
server{
listen 80;
#server_name mission13.io www.mission13.io;
server_name "~^www\.(.*)$";
return 301 $scheme://$1$request_uri;
root /usr/share/nginx/html/$1;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
include /usr/share/nginx/conf/mission13.io.conf;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
This block works:
server{
listen 80;
root /usr/share/nginx/html/diskise.com;
index index.php index.html index.htm;
server_name diskise.com www.diskise.com;
location / {
try_files $uri $uri/ /index.html;
}
include /usr/share/nginx/conf/diskise.com.conf;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
it is using a root that is set somewhere else, a completely different file.
I'm trying to install Symfony on my php5-fpm+nginx server on ubuntu.
When i'm entering to /web/app_dev.php it's displaying an error :
An error occurred while loading the web debug toolbar (404: Not
Found).
Do you want to open the profiler?
When i'm entering to profiler(/web/app_dev.php/_profiler/0db7ac) it tells:
No input file specified.
I know there is a problem with my server configuration file. Here it is:
server {
listen 80;
# listen [::]:80 ipv6only=on;
root /home/marker/Projects/stereoshoots/www;
access_log /home/marker/Projects/stereoshoots/logs/access.log;
server_name stereoshoots.local;
index index.php index.html index.htm;
location / {
autoindex on;
# try_files $uri $uri/ #rewrite;
try_files $uri $uri/ /index.php;
}
# location #rewrite {
# rewrite ^/(.*)$ /index.php?q=$1;
# }
location ~* \.(jpg|jpeg|gif|css|png|js|ico|xml|txt)$ {
access_log off;
expires 30d;
}
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
What should i edit, to get symfony installed right?
Thanks!
I think the only thing left is to pass the uri to the index.php
try_files $uri $uri/ /index.php$request_uri
Do you really have index.php?
Try this:
index app_dev.php;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /app_dev.php/$1;
}
location ~ \.php {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_PORT 80;
fastcgi_param SERVER_NAME stereoshoots.local;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index app_dev.php;
}
Notice that I changed location ~ \.php$ to location ~ \.php
I try to make my production server to serve my applications in a same style as phpmyadmin is served. Like example.com/phpmyadmin and what I try to do is example.com/myappname.
My nginx/sites-available/default looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www;
index index.html index.htm index.php;
server_name _;
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /myapp {
root /var/www/myapp/public/;
index index.php;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
location ~ /\.ht {
deny all;
}
}
So if someone has a working conf for this, I would like to have it too!
Notice that your /phpmyadmin location has extra configuration to pass the request to PHP-FPM via the fast_cgi configurations.
You'll need to do that for your /myapp location as well.
You may want to change your myapp location to something like this:
location ^/myapp/(.+\.php)$ {
root /var/www/myapp/public/;
index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
For comparison, here is my Laravel nginx configuration - however I don't have my app running under a "sub-directory".
Try changing some configuration items to see what you can get to work. Note that I removed fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; from the Laravel app location - I dont believe it is necessary.
Lastly, would this make more sense on ServerFault? You may get better answers there.