codeigniter not working in nginx(running on localhost), linux mint - php

I have installed LEMP on my linux mint system.
nginx is configured to work with php5-fpm sockets.
When I run codeigniter in my system index.php(link: localhost/ci/index.php) shows up, but when I try to open any of controller, say blog(link localhost/ci/index.php/blog) nginx gives 404 error message.
Following is my nginx configuration placed in file /etc/nginx/sites-avaliable/default
server {
listen 127.0.0.1:80;
listen [::]:80 default_server ipv6only=on;
root /home/scoders/Workspace/public_html;
index index.html index.htm index.php;
autoindex on;
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/scoders/Workspace/public_html/ci/index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Contents of nginx.conf are as follows:
user scoders;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
}
My log gives following error:
2016/03/14 14:38:38 [error] 23239#0: *1 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: 127.0.0.1, server: localhost, request: "GET /ci/index.php/ci
HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost"
I have tried these links but no luck:
Codeigniter | NGINX
CodeIgniter NGINX Rewrite Rules

Either /home/scoders/Workspace/public_html/ci/index.php is inaccessible for some reason or SCRIPT_FILENAME is being overridden in include fastcgi_params;
As a general rule, you should include first and fastcgi_param after.
For example:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Also, if your default URI is /ci/index.php and not /index.php, change your location / to:
location / {
try_files $uri $uri/ /ci/index.php?$args;
}

Related

Nginx unable to access parts of the website

Si I'm trying to run Invision Forums on nginx but it can't seem to access the uploads folder for some reason. It's most likely my configuration that's wrong but I'm not really sure since this is the first time I'm working with nginx.
Here's my configuration file:
worker_processes 1;
user www-data;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
listen [::]:80;
server_name localhost;
root /var/www/forums;
index index.php;
charset utf-8;
client_max_body_size 100M;
fastcgi_read_timeout 1800;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}

Nginx virtual block on Mac pointing to localhost's index.php

I am configuring virtual host to serve .localhost domain on my mac. But when I open "project.localhost" in my browser it shows the same page as, browsing the index of localhost. (ps: I've also configured dnsmasq and /etc/hosts). (trying to serve index.php)
Here is my nginx.conf:
worker_processes 1;
events {
worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
client_max_body_size 50M;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root html;
location / {
# root html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
# root html;
}
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include servers/*; }
and here is sites-available:
server {
listen 80;
listen project.localhost:80;
server_name project.localhost;
location / {
root html/project.localhost/public_html;
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
root html/project.localhost/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
and here is dnsmasq.conf:
address=/.localhost/127.0.0.1
and here is /etc/hosts:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 project.localhost www.project.localhost
but when I browse project.localhost in my browser it shows same page as localhost/index.php. What am I doing wrong?
As #Richard mentioned in the comment section I was able to solve the issue by including sites-available/*.conf: include /usr/local/etc/nginx/sites-available/*.conf, just before include server/* into my nginx.conf. Thank you #Richard

phpmyadmin and nginx gives no input file

This is my primary conf file
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mysite.com www.mysite.com;
root /home/mysite/www;
sendfile off;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
index index.php index.html index.htm;
location / {
}
location /pma {
alias /usr/share/phpmyadmin;
location ~ \.php$ {
try_files $uri #php;
}
}
location #php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
The phpmyadmin files are in /usr/share/phpmyadmin/
If I go to www.mysite.com/pma/ it gives me
No input file specified
And in error log :
2016/06/12 15:48:47 [error] 15999#0: *1 FastCGI sent in stderr: "Unable to open primary script: /home/mysite/www/pma/index.php (No such file or directory)" while reading response header from upstream, client: my-ip, server: mysite.com, request: "GET /pma/ HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "my server ip"
I've tried everything, changing alias with root also didn't help, it was downloading the index.php file to a file named 'download'
I've read that I should use alias instead of root. But it did not seem to solve my problem...
EDIT
i also have this inside default.d which is included
# pass the PHP scripts to FastCGI server
#
# See conf.d/php-fpm.conf for socket configuration
#
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm;
}
Please change alias to root ,and make sure correct path to your phpmyadmin in /usr/share/pma.
in this config use socket php-fpm. and sorry for my bad english
# # configure phpmyadmin path
location /pma {
root /usr/share;
index index.php;
location ~ ^/pma/(.+\.php)$ {
try_files $uri $uri/ /index.php?$args;
root /usr/share;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
#fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
}
location ~* ^/pma/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share;
}
}

nginx rewrite rules codeigniter

i am using Winginx for using nginx php and mysql on windows.
i want run and config CodeIgniter 2.
Winginx structure:
d:\winginx|
nginx.exe
php5\php.exe
mysql\mysqld.exe
\home\localhost\public_html\codeigniter
base this (http://wiki.nginx.org/Codeigniter)
and this (http://www.farinspace.com/codeigniter-nginx-rewrite-rules/)
and this (Nginx rewrite rule for CodeIgniter)
i try coonfig ci but i just see codeigniter 404 page (no nginx 404 page)
my ci config.php is
$config['base_url'] = "";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
..
nginx.config is
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid temp/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
client_max_body_size 55m;
#gzip on;
scgi_temp_path temp/uwsgi_temp 1 2;
uwsgi_temp_path temp/uwsgi_temp 1 2;
fastcgi_connect_timeout 1;
include codeigniter.conf;
}
i include codeigniter.conf in nginx.conf
codeigniter.conf is:
server {
listen 80;
server_name localhost;
root home/localhost/public_html/codeigniter:
autoindex on;
index index.php;
location / {
try_files $uri $uri/ /index.php?/$request_uri;
location = /index.php{
fastcgi_pass localhost:9000;
#fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
location ~ \.php$ {
return 444;
}
}
i try 3 different coonfig ci but i just see codeigniter 404 page (no nginx 404 page).
http://localhost/codeigniter/welcome/index -> CI 404 page!
http://localhost/codeigniter/welcome -> CI 404 page!
http://localhost/codeigniter -> CI 404 page!
i guest the problem is created by the php file location in codeigniter.conf
please help me to config it !
I'd try this
server {
listen 80;
server_name localhost;
root home/localhost/public_html/codeigniter;
autoindex on;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location = /index.php {
fastcgi_pass localhost:9000;
#fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location ~ \.php$ {
return 444;
}
}
Here's what I use for a production CI install
server
{
listen 80 default_server;
server_name www.site.com;
root /var/www;
index index.php;
# canonicalize codeigniter url end points
location ~ ^/index.php/(.*[^/])$ { return 301 $scheme://$host/$1/$is_args$args; }
location ~ ^/index.php/(.*)/$ { return 301 $scheme://$host/$1/$is_args$args; }
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
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 got it working the following way...
server {
listen 127.0.0.1:80;
server_name xxxx www.xxxx;
root home/xxxx/public_html;
autoindex on;
index index.php;
location / {
try_files $uri $uri/ /index.php?/$request_uri;
location ~ \.php$ {
if (!-e $document_root$document_uri){
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location ~ \.php$ {
return 444;
}
}

NGINX - Mapping html files to php

I cannot make nginx read php code embedded in .html files for a specific directory (html/test). I run CentOS 6 and have FastCGI installed. I have tried several configurations, but nothing does the job. My nginx.conf looks like this:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name www.domain.com;
rewrite ^(.*) http://domain.com$1 permanent;
}
server {
listen 80;
server_name shop-munk.com *.shop-munk.com;
location / {
root /opt/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/html;
}
location ~ \.php$ {
root opt/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.html$ {
root opt/html/test;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.html;
fastcgi_param SCRIPT_FILENAME /$fastcgi_script_name;
include fastcgi_params;
}
}
}
I was trying to do the same thing and server returned "403 Forbidden" for scripts without .php extension.
Following PHP-FPM configuration fixed the problem:
security.limit_extensions = .php .html

Categories