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;
}
}
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 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; }
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 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.
So while following this tutorial to implement two website on my NginX server.
Lin to the Website
I created two folder as follow
sudo nano /etc/nginx/sites-available/ideconnect.com
my file look like this
server {
listen 80;
listen [::]:80;
root /var/www/ideconnect.com/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name ide-portal.com www.ide-portal.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
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;
}
}
Then the other website
sudo nano /etc/nginx/sites-available/iclock.com
server {
listen 80 ;
listen [::]:80;
root /var/www/iclock.com/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name iclock.in www.iclock.in;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
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;
}
}
Also I have created the SYMLINKS properly
sudo ln -s /etc/nginx/sites-available/ideconnect.com /etc/nginx/sites-enabled/ideconnect.com
sudo ln -s /etc/nginx/sites-available/iclock.com /etc/nginx/sites-enabled/iclock.com
After this when I got to my ip address I can only see the default Nginx Page also now the info.php configuration page is also not visible.
Any help would be appreciated
Thanks
There are two things you can check to begin with:
Did you restart nginx?
Are you sure your nginx configuration is set up to include .com files? I think the default is to include all .conf files. You can check that in your nginx configuration file and then adapt that or modify the extension of your symlinks.