Yii application 404 not found with nginx server - php

I tried to run the yii application on my vps which is installed with nginx as a server. but when I access my domain: www.domain.com, pages appear fine but if one link is always accessed 404 not found error. Is there something wrong with my nginx settings?
My nginx configuration :
server {
listen 80;
server_name www.mydomain.com;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

below the index line add this line
try_files $uri $uri/ /index.php$request_uri;

Related

Configuring NGINX for a cakephp web project 404 not found in Amazon Linux AMI

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

Nginx how to redirect request for only a certain directory path to index.php in that directory?

I have some websites like
http://localhost/myweb1
http://localhost/myweb2
and so on.
I need to redirect below example request for myweb1 to index.php in http://localhost/myweb1/index.php
while myweb2 should not be affected.
http://localhost/myweb1/user
http://localhost/myweb1/user/account
http://localhost/myweb1/product
and so on should be redirected to myweb1/index.php
Below is my config at /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index 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 /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
root /usr/share/nginx/html;
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Answer provided by
#RichardSmith
root /usr/share/nginx/html;
location /myweb1 { try_files $uri $uri/ /myweb1/index.php; }

Running WordPress on Nginx Keeps Downloading File

I am trying to run Wordpress on my NGinx server, however I think that something is wrong because the index.php file keeps downloading rather than being run.
here is my sites-available:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
server_name your_domain.com;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I checked to make sure that I had php7.1-fpm running and that my nginx was running as well. Both checked out to be just fine.
What am I missing?
Thanks
This link solved my problem. I was missing some packages that wordpress needed. After going through that guide everything worked

NGINX server directives to reach an API

I have a LEMP server and I'm looking to install RespondCMS (http://respondcms.com/documentation/install-on-digital-ocean). I'm running into some difficulties with the mod_rewrite section for an API. I've tried several iterations but have been unable to get it to show an "API works" message that indicates the PHP app is working. I get a 404. Thus far, I have settled on the following set-up in my /etc/nginx/sites-enabled/. I'm thinking it's not accessing the /api folder correctly. Any help in understanding how it's all interacting and how to make it work is appreciated.
app.domain.com
server {
listen 80;
server_name app.domain.com;
root /srv/www/domain_app/app;
index index.php index.html index.htm;
access_log /var/log/nginx/respond.access.log;
error_log /var/log/nginx/respond.error.log;
location /api/ {
try_files $uri $uri/ /api/dispatch.php$args;
}
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /srv/www;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
domain.com
server {
listen 80 default_server;
root /srv/www/html;
index index.php index.html index.htm;
server_name domain.com;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
The URL http://app.domain.com/api/dispatch.php is processed by the location ~ \.(hh|php)$ block. And that block seems to be configured (reasonably) correctly.
You should move include fastcgi_params; above any fastcgi_param directive to avoid the latter being inadvertently overridden. And the fastcgi_index directive is redundant in this context.
Both the location / and location /api/ blocks have issues. The alias directive is unnecessary and wrong. All three locations inherit their root from the outer server block. You should delete both alias directives.
In your try_files $uri $uri/ $uri.php /api/dispatch.php$args; statement, the $uri.php element will cause the PHP file to be downloaded rather than executed. Only the last element of a try_files directive can take an action that is not processed within the same location block. If you really need to execute extension-less PHP URIs and have a default PHP URI too, you will probably need to use a named location.
A useful resource for all nginx directives is here.

cannot access file .php inside webroot in cakephp with nginx

I have VPS with this specification:
Ubuntu
Nginx
Php
MySql
So I make project with CakePHP in subfolder named gogon. This project can running and access perfectly. The site url can access at example.com/gogon
problem
I put responsivefilemanager (responsivefilemanager.com) in webroot folder as filemanager, but when I want to access the PHP file in filemanager (dialog.php) site just render my index.php file like example.com/index.php
Structure of my folder:
-example.com
---index.php
---gogon (cakephp project)
-----index.php
-----app
---------config
---------...
---------...
---------...
---------webroot
-------------filemanager
----------------dialog.php
-----lib
-----plugin
-----vendor
This is my nginx config
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ $uri.php /index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location /gogon {
rewrite_log on;
error_log /usr/share/nginx/error.gogon.log error;
if (-f $request_filename) {
break;
}
# Avoid recursivity
if ($request_uri ~ /webroot/index.php) {
break;
}
rewrite ^/gogon$ /gogon/ permanent;
rewrite ^/gogon/app/webroot/(.*) /gogon/app/webroot/index.php?url=$1 last;
rewrite ^/gogon/(.*)$ /gogon/app/webroot/$1 last;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~* \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Categories