I did the following configurations for nginx server for code igniter and worked correctly , unfortunately there is one case not working.
When I request URL with parameter Like
servername.com/ControllerName/methodName?param=value
I got Not found Page 404
Server Configurations :
server {
# access from localhost only
listen 127.0.0.1:80;
server_name serverName.com;
root API;
log_not_found off;
charset utf-8;
access_log logs/accessservername.log main;
index index.php;
# handle files in the root path /www
location / {
try_files $uri $uri/ /index.php?$args;
}
#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 API;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9100
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php;
fastcgi_index index.php;
#fastcgi_param PHP_FCGI_MAX_REQUESTS 1000;
#fastcgi_param PHP_FCGI_CHILDREN 100;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REMOTE_ADDR $http_x_real_ip;
include fastcgi_params;
}
# add expire headers and speed up image access with a vary header
location ~* ^.+.(gif|ico|jpg|jpeg|png|flv|swf|pdf|mp3|mp4|xml|txt|js|css)$ {
expires 30d;
add_header Vary Accept-Encoding;
}
# only allow these request methods
if ($request_method !~ ^(GET|HEAD|POST)$ ){ return 405; }
}
Related
I have a problem during configure nginx in Amazon Linuz AMI, I installed nginx on Amazon Linuz AMI and pulled my cakephp project into /var/www/html. But the problem is that when I try to access to the index.php file into the webroot folder with nginx I have a 404 Not Found error.
Do you have any suggestion ?
Here is my Config nginx file:
server {
root /var/www/html/orangescrum;
server_name payzilla.in www.payzilla.in;
index index.html index.htm index.php;
access_log /var/log/nginx/app_access.log;
error_log /var/log/nginx/app_error.log;
try_files $uri $uri/ /index.html;
location / {
try_files $uri $uri/ /index.php?$uri&$args;
rewrite ^/$ /app/webroot/ break; rewrite
^(.*)$ /app/webroot/$1 break;
}
location ~ \.(php|phar)(/.*)?$ {
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/mydomain/html$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php-fpm;
}
location ~ /\.ht {
deny all;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
Please provide the Best Configuration file for both http and https for Amazon Linux AMI
We also need to set up the SSL part also
I open any other page it always opens up index page, routes are not properly working for phalcon app. whenever i try to open other page with different route it always open index page. My nginx.conf is below, Please check and suggest for correction.
server {
listen 85;
server_name localhost;
#charset koi8-r;
root abc.example.com;
index index.html index.htm index.php;
#access_log logs/host.access.log main;
autoindex on;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
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;
fastcgi_intercept_errors on;
}
#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;
}
# general static
location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ {
root abc.example.com;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
I am building a website based on angularjs and nginx server.I am struggling at url rewrite for angularjs , I used my development environment as apache which is working well.I want to use extensionless php so that if i visit www.mywebsite.com/register it points to www.mywebsite.com/register.php . When I put slash near www.mywebsite.com/register/it is not working.For angular I want the url as www.mywebsite.com/register/step2 to www.mywebsite.com/register/#!/step2
server {
server_name mywebsite.com;
return 301 $scheme://www.mywebsite.com$request_uri;
}
server {
listen 80;
server_name localhost www.mywebsite.com;
#charset koi8-r;
#access_log /var/log/nginx/log/india.access.log main;
location / {
root /var/www/mywebsite;
index index.php index.html index.htm;
}
location ~ /register/ {
rewrite ^ register.php/#/$1 redirect;
break;
}
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 /var/www/mywebsite;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location /api/ {
try_files $uri $uri /api/index.php?$query_string;
}
location ~ \.php$ {
if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1?$args; }
root html;
#include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/mywebsite$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
error_page 404 /404;
}
location #extensionless-php {
rewrite ^(.*)$ $1.php last;
}
# if enable status in PHP-FPM config
location ~ ^/(status|ping)$ {
allow 127.0.0.1;
#deny all;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
I have configured my nginx to get data from s3 in case of 502 error thrown by php, but it is accessing data for all requests even when there is no 502 error.
Here is my configuration file,
upstream php {
server unix:/var/run/php5-fpm.sock;
}
server {
listen *:80;
server_name x.x.x.x;
root /data/www/public/;
# access_log /var/log/nginx/www.example.com.access.log main;
error_log /var/log/nginx/wf_err.log;
add_header Access-Control-Allow-Origin http://x.x.x.x;
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
index index.php;
try_files $uri $uri/ /index.php;
}
location #static{
add_header Access-Control-Allow-Origin *;
rewrite ^ $request_uri;
rewrite ^/assets/(.*)/(.*)\.css.* /assets/$1/$2.css break;
rewrite ^/assets/(.*)/(.*)\.js.* /assets/$1/$2.js break;
rewrite ^/assets/image.*/(.*)\.(.*).* /assets/image/$1.$2 break;
rewrite ^/assets/fonts/(.*)\.(.*).* /assets/fonts/$1.$2 break;
rewrite /story/([0-9]+)/([0-9]+)/.* /story/$1/$1_$2.html break;
rewrite /story/([0-9]+)/.* /story/$1/$1_1.html break;
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_pass http://bucket.s3.amazonaws.com;
}
location ~ \.php {
try_files $uri =404;
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
error_page 502 504 503 #static;
fastcgi_intercept_errors on;
# return 502;
}
# deny access to .htaccess files
location ~ /\.ht {
deny all;
}
}
I have used fastcgi_intercept_errors to catch errors sent by php.
Then, using error_page directive, I change the location to #static, where the requests are processed from s3.
But I can't understand why all requests are going to s3 even when there is no error.
Thanks.
So, I have next problem. This is my nginx config
server {
disable_symlinks off;
listen 80;
server_name g9tv.loc;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root /home/dejmos/www/g9tv;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php;
}
error_page 404 /index.php;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/dejmos/www/g9tv;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
root /home/dejmos/www/g9tv;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/dejmos/www/g9tv$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
When I go to page that not exists on server I got 404 page provided by nginx, but I need to get 404 page provided by codeigniter show_404() function.
Problem resolved. It caused by subfolder. I place Codeigniter to root folder and all ok now.