I am trying to setup a Nginx / PHP-FPM server on my raspberry Pi (Debian) and I am having trouble getting the php to work correctly.
Text displayed on webpage: This Page is Temporarily Unavailble
I have checked the nginx logs and there are no errors being recorded.
This is my nginx.conf:
# Pi Nginx Config v0.1 10:53 30/01/2014
# NOTE: fastcgi is NOT php5-fpm
server {
listen 1080;
# server_name mysite.org;
charset utf-8;
access_log off;
root /var/www/cms;
index index.php;
location / {
try_files $uri $uri/ /index.php?id=$uri&$args;
}
location ~* /admin/.*\.php$ {
try_files $uri /admin/index.php?id=$uri&$args; # Try the admin index page
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~* \.php$ {
try_files $uri =404; # Try any .php files in root or throw a 404
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in /etc/php5/fpm/php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
expires 2h;
}
location ~* \.(?:ico|js|gif|jpg|png)$ {
expires 14d;
}
location ~* \.(htm|css|html)$ {
expires 2d;
}
# this blocks direct access to the XML files (but sitemap.xml) - that hold all the data
location ~* \.xml$ { deny all; }
location ~* \.xml\.bak$ { deny all; }
location = /sitemap.xml { allow all; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { deny all; }
location ^~ /uploads/ {
if ($request_uri ~* \.php$) {return 403;}
}
}
I do not have enough experience to see anything wrong with this config. My server is on port 1080 and the server root is within the cms directory.
Any help would be greatly appreciated.
Related
I have deployed a Drupal site that was developed on DigitalOcean Ubuntu onto AWS EC2 Ubuntu. So essentially the directory structure and configuration files are copied from DigitalOcean VPS. But the site on DigitalOcean is accessible while that on AWS throws a ERR_CONNECTION_REFUSED error on the browser.
I have beenn trying for several hours and haven't found any reason why the AWS site doesn't load. There are no error and access log messages in /var/log/nginx
My /etc/nginx/nginx.conf has the following line so I am sure the configuration files in /etc/nginx/sites-enabled folder are being read by Nginx.
include /etc/nginx/sites-enabled/*.*;
The /etc/nginx/sites-enabled has sym links to /etc/nginx/sites-available directory and the /etc/nginx/sites-available/domain.conf contains the following
server {
listen subdomain.domain.biz;
server_name subdomain.domain.biz;
root /home/sridhar/public_html/domain/public;
keepalive_timeout 70;
access_log /home/sridhar/public_html/domain/log/access.log;
error_log /home/sridhar/public_html/domain/log/error.log;
# Enable compression, this will help if you have for instance advagg ^ modue# by serving Gzip versions of the files.
gzip_static on;
index index.php;
#index index.php index.html index.htm;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(txt|log)$ {
allow 192.168.0.0/16;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
# No no for private
location ~ ^/sites/.*/private/ {
return 403;
}
location ~ (^|/)\. {
return 403;
}
location / {
try_files $uri $uri/ #rewrite;
expires max;
}
location #rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
#fastcgi_pass unix:/tmp/phpfpm.sock;
fastcgi_pass 127.0.0.1:9000;
}
location ~ ^/sites/.*/files/styles/ {
try_files $uri $uri/ #rewrite;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
Is there any specific configuration that needs to be cariied out for AWS EC2? Or have I missed something.
i need your help with setting location allow,
location /route {
deny [my-ip];
}
So this works, it doesn't let me access the route
Throws this error
403 Forbidden
nginx/1.10.0 (Ubuntu)
And this...
location /route {
allow [my-ip];
deny all;
}
Doesn't let me access but it's supposed to let me access the route, can't understand why, it shows this error
404 Not Found
nginx/1.10.0 (Ubuntu)
Config file (with two examples on routes):
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
server_name [my-domain];
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
# Phpmyadmin Configurations
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS on; # <-- add this line
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.
(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
# Dealing with the uppercased letters
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
location /logs {
deny [myip];
}
location /admin {
allow [myip];
deny all;
}
for anybody else who is searching for the solution. This did it for me after long try and error:
location = /phpmyadmin/index.php {
allow 1.2.3.4;
deny all;
....
}
Make sure you use the "=" sign or else it won't work.
So your problem is not the allow and deny. It is root /usr/share/; Since you have placed it into a location block location /phpmyadmin, it can not be found by location \admin therefore, it returns 404. Try to place the root /usr/share/ to the server block instead of a location block.
I have 2 nginx configurations. Both of them work well alone. One of them is for drupal (frontend) and one of them is the backend. At the end I would like to have mydomain.com/ = frontend & mydomain.com/backend = backend.
Unfortunately I don't know what I have to do to make this work.
Here both configs:
//Drupal
upstream fcp {
server unix:/var/run/php-fpm.sock;
}
server {
listen 80;
server_name www.example.com;
root /usr;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass fcp;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
}
// ====== //
// Backend-Software
upstream backend{
server unix:/var/run/php-fpm.sock;
}
server {
[...]
server_name www.example.com;
root /usr/backend/wwwroot;
#Generic definition
location / {
index index.php;
try_files $uri $uri/ /index.php?route=$uri&$args;
}
#backend.net frontend controller (redirect these calls to PHP-FPM)
location ~ ^/index.php {
fastcgi_pass backend;
fastcgi_param SCRIPT_FILENAME /usr/backend/wwwroot$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# Internal link to the files for X-Accel support
location /_files {
internal;
alias /usr/backend/_files/filesource/;
}
#Static Resources
location /wwwres/ {
expires 365d;
alias /usr/backend/wwwres/;
}
location ~ ^/wwwres/mod/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/modules/$1/wwwres/$2;
}
location ~ ^/wwwres/vendor/([^/\.]*)/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/vendor/$1/modules/$2/wwwres/$3;
}
location ~ ^/wwwres/theme/set_([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/_files/theme_set/$1/$2;
}
location ~ ^/wwwres/theme/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/themes/$1/wwwres/$2;
}
location ~ ^/wwwres/vendor_theme/([^/\.]*)/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/vendor/$1/themes/$2/wwwres/$3;
}
location ~ ^/_cache/(.*)$ {
expires 365d;
alias /usr/backend/_cache/$1;
}
#Error Pages
error_page 404 /static/error/404.php;
error_page 500 504 /static/error/500.php;
error_page 502 /static/error/502.html;
error_page 503 /static/error/503.php;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
I think you can merge these configurations into one server section. The root in this section can be /usr (from first section - is this correct?) or /usr/backend/wwwroot. You should decide which will be the default (www.example.com): the /usr/index.php or the /usr/backend/wwwroot/index.php. As I see you want /usr/index.php so your root should be /usr. And should add
location /backend {
root /usr/backend;
...
}
The location /_files and "Static Resources" will right because you use alias in every section.
Summary:
http {
server_name example.com;
root /usr;
index index.php;
location /backend_uri {
alias /usr/backend; # if "backend_uri"=="backend" (and root is /usr) this section is unnecessary
}
location /_files {
# same as your post
}
# Static resources
# same as your post
}
I have a perfect configuration which is nginx, php5-fpm, apc, varnish and mariadb. Everything works flawless except;
I am hosting a single web site, since my server resources are high and available, I want to host other web sites on the same server. When I try to add different websites into nginx the service simply does not restart.
here's my configuration file when everything works:
server {
listen 8080;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name www.domain1.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
I don't want to use seperate files for different virtual hosts, I want to do everything in default file. But when I add another virtual host like below and save default file. nginx won't restart.
server {
listen 8080;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name www.domain1.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
server {
listen 8080;
root /usr/share/nginx/domain2;
index index.php index.html index.htm;
server_name www.domain2.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
Please help me resolve this issue. I think something is conflicting but don't know what.
ok I found the solution just by investigating error log.
2014/08/19 21:55:07 [emerg] 5927#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
error log tells me to increase hash bucket size..
I edited nginx.conf and set the bucket size to 32 as advised in error log, it didn't work at first, but then I set it to 64 and it worked.
just search for "bucket" in nginx.conf, uncomment it, then set to 64 (or above in some cases) it will work, unless there is another issue.
I want to migrate my wordpress installation from apache to nginx. Actually everything is working (at least it seems so) but the rewriting of urls.
My setup:
php-fpm on unix instead tcp socket
wordpress installation in /var/www/blog/
ubuntu 12.04 lts
nginx 1.1.19
Following the nginx documentation for wordpress I tried to add
location /blog {
try_files $uri $uri/ /wordpress/index.php?$args;
}
location ~ \.php$ {
# ...
fastcgi_split_path_info ^(/blog)(/.*)$;
}
But this is still not working for me. Do you have any ideas?
# /etc/nginx/sites-enabled/default
server {
listen 80;
root /var/www/blog;
index index.php;
server_name 12.34.56.789; # server isn't connected with a domain for now
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { allow all; log_not_found off; access_log off; }
location ~ /\. { deny all; }
location ~* /(?:uploads|files)/.*\.php$ { deny all; }
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(/blog)(/.*)$;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
also changed www.conf
# /etc/php5/fpm/pool.d/www.conf
# ...
listen = /var/run/php5-fpm.sock
# ...
php.ini changed cgi.fix_pathinfo
# /etc/php5/fpm/php.ini
# php.ini
# ...
cgi.fix_pathinfo=0
# ...