I have my website stored in /usr/share/nginx/html .gave 777 to all directories and files.when i fire-up the browser and navigate to website, it downloads the page rather than displaying it.
php-fpm is installed and running
this my /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name hostedweb.net;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php 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$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$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;
#}
}
I'm on CentOS 6
any help is appreciated
In your location ~ \.php$ { try adding include fastcgi_params;
Also in your php portion you could try taking out the root html; portion, or try setting it to root /usr/share/nginx/html;
Have you tried removing or commenting out fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;? I don't have that line in any of my nginx config files and they seem to work fine.
Did you try adding
try_files $uri $uri/;
To your location / {} block
And I believe you don't need this line
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
because you included the fastcgi_params
Related
I have been installed php-fpm and tengine centos 6.
Here is my /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
proxy_pass http://127.0.0.1;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME/$document_root$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;
}
}
http://172.104.126.251/index.html Work!
But
http://172.104.126.251/index.php can't work, it appear error page.
Hope you guys can help me, thanks!
My Laravel app is returning 404 on every route.
This is the address: http://67.205.191.11/, when I try for example http://67.205.191.11/classes, 404 not found is returned.
my nginx default config file looks as below:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/venture-backend/public/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name 67.205.191.11;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#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;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}
Anyone knows why my routes are not working?
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.
I'm getting a 404 error in nginx, when I should be getting a redirection instead.
I come from Apache and this is the first time I play with Nginx.
I suppose it has to be a minor mistake that I'm overlooking.
This is the code:
server {
listen 80 default_server;
server_name localhost;
root /var/www/resizing/public_html;
index index.php index.html index.htm;
location ~ ^/(.*)/cache/(.*)$
{
try_files $uri #resize;
expires 4h;
}
location / {
expires 4h;
}
location ~ \.php(.*)$ {
#fastcgi_pass 127.0.0.1:8000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location #resize {
rewrite ^/(.*)/cache/(.*)$ /resize.php?dir=$1&path=$2;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#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;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# try_files $uri =404;
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}
For instance if I type: localhost/cache/150x200-0/originals/1.jpg I get a 404error.
The problem is that the URI is /cache/150x200-0/originals/1.jpg, and it isn't matched by the location ~ ^/(.*)/cache/(.*)$ in your configuration.
Correct location will look like (assuming the "dir" component is actually needed):
location ~ ^(/.*)?/cache/(.*)$ {
...
}
Note well that the same problem is present in the rewrite used in the location #resize.
I setup a nginx server in my localhost
So now I want to enable clean url for this server
(Change localhost/drupalsite/?q=abc to localhost/drupalsite/abc)
I have tried some tutorials but thet don't work for me
http://wiki.nginx.org/Drupal
https://drupal.org/node/976392
http://richardbanks.net/blog/2012/11/nginx-url-rewrites-the-correct-method
This is some basic config in nginx.conf file
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /srv/nginx/www/nginx_htdocs/;
index index.html index.htm index.php;
}
#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 /srv/nginx/www/nginx_htdocs/;
}
# 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$ {
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;
fastcgi_param SCRIPT_FILENAME /srv/nginx/www/nginx_htdocs/$fastcgi_script_name;
include fastcgi_params;
}
#--------------- TUNG CUSTOM
#------------- END CUSTOM
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Here's a gist of a full configuration that works very well with Drupal's clean URL's
You must try to handle not found urls as possible query strings for index.php (if that's how Drupal works, which I'm not sure).
For example, in your first location block:
location / {
root /srv/nginx/www/nginx_htdocs/;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$request_uri;
}
This way, if
`http://mysite.com/xyz`
doesn't match any file or folder, it gets handed to index.php in the form of
`http://mysite.com/index.php?xyz`