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;
}
}
Related
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;
}
}
}
I am the beginner for nginx
I am tryingt to do
www.mywebsite.com/index.php to show in the url like www.mywebsite.com/
and
www.mywebsite.com/index.php/user/login to show in the url like www.mywebsite.com/user/login
and I got the error as show in the picture.
Here is my nginx.config
#user nobody;
worker_processes 4;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.wcp6288.com;
root /var/www/wangou;
index index.html index.htmi index.php;
#charset koi8-r;
#access_log logs/host.access.log main;
if ($request_uri ~* "^(.*/)index\.php$") {
return 301 $1;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
# Remove from everywhere index.php
if ($request_uri ~* "^(.*/)index\.php(/?)(.*)") {
return 301 $1$3;
}
}
# Remove trailing slash.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# Clean Double Slashes
if ($request_uri ~* "\/\/") {
rewrite ^/(.*) /$1 permanent;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/wangou/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
try_files $uri $uri/ =404;
}
}
}
Thanks you for your helps.
Should you remove
try_files $uri $uri/ =404;
In block:
location ~ \.php$ {
root /var/www/wangou/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
try_files $uri $uri/ =404;
}
Here is my config and it's worked.
server {
listen 80;
listen 443 ssl http2;
server_name test.dev;
root "/var/www/html/test/";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
access_log off;
error_log /var/log/nginx/test.dev-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
I am pretty new in Nginx and I have a problem with it. I have two wordpress websites and I want to start them with Nginx on a Centos Linux. What I have done is:
creating sites-available and sites-enabled in the /etc/nginx/
Put my website configuration files (.conf) into sites-available
I created symbolic links for them using ln -s
My configuration files are as follow:
nginx.conf
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;
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 _;
root /usr/share/nginx/html;
index index.html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
}
mydomain1.com.conf
server {
listen 80;
server_name mydomain1.com www.mydomain1.com;
location / {
root /var/www/html/;
index index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
mydomain2.com.conf
server {
listen 80;
server_name mydomain2.com www.mydomain2.com;
location / {
try_files $uri $uri/ =404;
root /var/www/aramis;
index index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
/etc/php-fm.d/www.conf
[www]
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
;listen.mode = 0660
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
I also tried to find php-fpm.sock but I was not successful.
What I get when try to see my websites from browser is 404 Error.
You have no root directive for your PHP location block. If it is the same root for all files (both static and dynamic) then move the root directive to the server block and allow the same value to be inherited by both location blocks.
server {
...
root /var/www/aramis;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
...
}
}
See this document for more.
Your need resolve the redundance
mydomain1.com.conf
server {
listen 80;
root /var/www/html/; # Set as global
server_name mydomain1.com www.mydomain1.com;
index index.php # Set index as global
location / {
# index index.php; #Remove this line
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
myworkingfile.conf
server {
listen 80;
server_name crm.coderic.net;
root /var/www/atrk/crm.atrk.com.co/public;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
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;
}
}
My site keep showing phpinfo(); when I land on it
My root should be : /home/forge/aveniros/public
I'm not sure where to set it.
I decide to configure my settings in : ~/etc/nginx/sites-available/default
server {
listen 80 default_server;
server_name
default;
root / home / forge / aveniros / public;
index index.html index.htm index.php;
#
FORGE SSL(DO NOT REMOVE!)# ssl_certificate;#
ssl_certificate_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf - 8;
location / {
try_files $uri $uri / /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /
var / log / nginx /
default -error.log error;
error_page 404 / index.php;
location~\.php$ {
fastcgi_split_path_info ^ (. + \.php)(/.+)$;
fastcgi_pass unix: /var/run / php5 - fpm.sock; fastcgi_index index.php; include fastcgi_params;
}
location~/\.ht {
deny all;
}
}
Then, I run sudo service nginx restart after I saved.
Nothing seem to take effect.
Can someone please tell me what did I do wrong here ?
You need to set your server name to _, currently you are only listening to requests to the name default.
server_name _;
Use this virtual host
server {
listen 80;
server_name project.dev;
root /var/www/directory/project/public;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php/?(.*)$ {
fastcgi_connect_timeout 3s; # default of 60s is just too long
fastcgi_read_timeout 10s; # default of 60s is just too long
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
}
My Site is working now. Here are my settings :
File Path : ~/etc/nginx/sites-available/default
server {
listen 80 default_server;
server_name default;
root /home/forge/aveniros/public;
#HTTP Authentication Configuartion
auth_basic "Restricted";
auth_basic_user_file /home/forge/aveniros/.htpasswd;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}