I'm getting a Access denied message any time I try to access the WebServer through http://dev or http://devserver address. I don't know what is wrong on my Nginx config. Below is the config.php and default site configuration:
/etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
## Load virtual host conf files. ##
include /etc/nginx/sites-enabled/*;
}
This file has a symbolic link to /etc/nginx/sites-enabled so it's enabled:
/etc/nginx/sites-available/default
server {
listen 80 default;
listen [::]:80 default ipv6only=on;
# Make site accessible from http://localhost/ or server IP-address
server_name dev devserver;
server_name_in_redirect off;
charset utf-8;
root /var/www/html;
index index.php index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then trigger 404
try_files $uri $uri/ =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /var/www/html;
# send bad requests to 404
fastcgi_intercept_errors on;
include fastcgi_params;
}
}
I'm on CentOS 6.6 with Nginx 1.6.2 and PHP 5.5.18 with PHP-FPM. Also I have SELinux disabled and the only thing I have there is Iptables. Other sites runs fine and by sites I mean any that points to the root directory, for example this one which is a Symfony2 project:
server {
server_name newsite.dev newsite.webvm newsite;
root /var/www/html/newsite.dev/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
access_log /var/log/nginx/newsite.dev/access.log;
error_log /var/log/nginx/newsite.dev/error.log;
}
In that case calling http://newsite.dev or http://newsite.webvm or http://newsite I get the expected result, the site but the first is not working and I do not know what else to do, so any help or advice around the configuration and why contents are not served?
Related
I am trying to set the slimframework on nginx webserver. Below is my current settings. I am using the slim/slim-skeleton. Whenever I run e.g. http://myip/apiv1 it points to the index.php in /var/www/html. Even I run anything example http://myip/apiv1/token its the same as above. I tried changing the root /var/www/html/apiv1/public; to alias /var/www/html/apiv1/public; its the same. What else does nginx require any special settings.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server_tokens off;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/blockuseragents.rules;
limit_conn_zone $binary_remote_addr zone=addr:5m;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
#root /usr/share/nginx/html;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ index.php?$query_string;
}
location /apiv1 {
root /var/www/html/apiv1/public;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 444;
}
limit_conn addr 1;
}
I tried to find out the solution online but every solution is different. no one is working. I just migrated our web server from Apache to Nginx and I am getting 404 error. Here is the php info: http://likeopedia.net/info.php. If you visit main domain then you will see the error.
I am facing some serious problems for this setup. Our site is working on Apache server but not on Nginx.
here is nginx.conf file that I have changed a little bit.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
autoindex on;
index index.php;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html;
include /etc/nginx/default.d/*.conf;
index index.php index.html index.htm;
rewrite_log on;
location / {
try_files $uri $uri/ /index.php;
location = /index.php {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
}
location ~ \.php$ {
return 444;
}
and here the codeigniter confiq.php file:
$config['base_url'] = 'http://likeopedia.net';
$config['abs_path'] = $_SERVER['DOCUMENT_ROOT'].'/';
$config['logout_url'] = 'http://likeopedia.net';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
It is now in development mode.
You have enclosed the location = /index.php inside the location /. Try changing the location / so that it does not enclose location = /index.php.
It should look like this:
location / {
try_files $uri $uri/ /index.php;
}
location = /index.php {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
return 444;
}
Give it a try and let us know if this helps.
Thank for the feedback - here is what I think you can try as well:
Remove the location = /index.php and instead try the following configuration for the location ~\.php$ declarative:
location ~ \.php$ {
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;
}
I'm trying to figure out why I keep receiving a file not found.
I have a directory with multiple directories within that contain php files in them. I'm not sure how to configure my conf file to execute these files.
I get the following in the error log.
*133 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.8.1, server: 172.17.8.101, request: "GET /design_files/tmpls/podcastSilk/L4_index.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "172.17.8.101:8001"
The directory structure of the application is as follows
/tmplbuilder
/design_files
/tmpls
/Folder2
L4_index.php
/Folder1
L3_index.php
/public
index.php
Here is my nginx.conf file.
daemon off;
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
client_header_timeout 60;
send_timeout 160;
client_max_body_size 50M;
fastcgi_keep_conn off;
gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/x-javascript text/xml text/css application/xml;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
index index.php index.html index.htm ;
server {
listen 80;
server_name 172.17.8.101 192.168.254.96;
root /var/www/tmplbuilder;
#try_files $uri $uri/ /index.php$uri /index.php?$args;
location ~* \.(jpg|jpeg|gif|png|html|htm|css|zip|tgz|gz|rar|doc|xls|pdf|ppt|tar|wav|bmp|rtf|swf|flv|txt|xml|docx|xlsx|js)$ {
try_files $uri $uri/ public$uri public/index.php$uri =404;
access_log off;
expires 30d;
}
location /design_files/ {
root /var/www/tmplbuilder/design_files;
try_files $uri $uri/;
#root /var/www/tmplbuilder/design_files;
#autoindex on;
location ~* \.php$ {
#try_files $uri $uri/ $document_root$fastcgi_script_name;
fastcgi_pass unix:/tmp/php-fpm.sock;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(.*)$;
#fastcgi_index L4_index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#return 200 $document_root$uri;
}
}
location /public/{
#return 200 $uri;
#alias /var/www/tmplbuilder/public;
root /var/www/tmplbuilder/public;
try_files $uri $uri/ /index.php index.php$uri$args;
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /public/index.php?/$1 last;
break;
}
location ~ \.php$ {
return 200 $uri;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
}
}
When I run return 200 $document_root$fastcgi_script_name. I get the appropriate path to the file in question. Is this the path nginx can't find? The permissions are 755 on the file.
Try matching the uri in regular expressions ($1) and then feed that as a script name to php-fpm.
location ~ ^(.*\.php)(.*)$ {
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$1;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
I'm fairly new to Linux and I'm having a little trouble setting up my web server... I am using LEMP with Varnish and phpMyAdmin. The server is running and I can access phpMyAdmin over https etc. Now I'm trying to setup Wordpress on another directory using the include /directory/*.conf; however it doesn't seem to load the file(s). It will only load the default directory set in nginx.conf
Here's my nginx.conf,
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/v-hosts/*.conf;
index index.php index.html index.htm;
server {
listen 127.0.0.1:8080;
root /usr/share/nginx/html;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
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;
}
location ~* ^/stolenmx.com/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /srv/www/;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
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;
}
}
server {
listen 443;
client_max_body_size 80M;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
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;
}
}
}
And here's my file i'm trying to load for wordpress,
server {
server_name stolenmx.com;
listen 8080;
access_log /var/log/nginx/stolenmx.com-access.log;
error_log /var/log/nginx/stolenmx.com-error.log;
root /srv/www/stolenmx.com;
location / {
index index.php;
}
# Disable favicon.ico logging
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Allow robots and disable logging
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Enable permalink structures
if (!-e $request_filename) {
rewrite . /index.php last;
}
# Handle php requests
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/stolenmx.com$fastcgi_script_name;
}
# Disable static content logging and set cache time to max
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
# Deny access to htaccess and htpasswd files
location ~ /\.ht {
deny all;
}
}
I have included this files directory in nginx.conf "include /etc/nginx/v-hosts/*.conf;" but for some reason it's not loading it and won't point the server_name to /srv/www/ ?
Does anyone have any suggestions as to why it won't load additional server.conf ?
I can drag the wordpress install into /usr/share/nginx/html and it works but then I can't have any more than one server. I think it's something to do with my nginx.conf but not sure what to change / add?
Regards Crafty
Before changes can affect you need to restart/reload your nginx, in CentOS it's done by running:
/etc/init.d/nginx restart
(If you are not root use sudo)
You are requiring that all your included files will be suffixed with '.conf', please make sure your file has this extension. Last thing, you configured your Wordpress server to listen on 8080, did you checked on this port?
I've got Freebsd 8 srv with nginx, php, mysql, phpBB forum, local extjs app, bugzilla, joomla and PhpMyAdmin (/pma)
The problem is when I go to pma and login through I'm redirected to domain_name/index.php?token... instead of /domain_name/pma/index.php?token...
Same thing happes when I login to joomla admin part (domain_name/administraton/index.php. redirected to domain_name/index.php)
I understand that is a location config issue probably, but i cant find out where it is.
Config below:
user www;.
worker_processes 4;
pid /var/run/nginx.pid;
error_log /var/log/nginx-error.log warn;
events {
worker_connections 1024;
use kqueue;
}
http {
gzip on;
gzip_static on;
gzip_vary on;
gzip_http_version 1.1;
gzip_min_length 700;
gzip_comp_level 6;
gzip_disable "msie6";
include mime.types;
default_type application/octet-stream;
# log options.
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
# nginx options
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
# fastcgi
fastcgi_intercept_errors on;
# virtual server
server {
listen 80;
server_name domain_name www.domain_name;
server_name_in_redirect off;
rewrite 301 http://domain_name$request_uri;
access_log /var/log/haim_access_log main;
error_log /var/log/haim_error_log error;
root /usr/local/www;
# phpBB: Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
# Joomla: caching of files
location ~* \.(ico|pdf|flv)$ {
expires 30d;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
# Joomla: deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
# error pages 40x
error_page 404 /40x.html;
location = /nginx-distr/40x.html {
}
# phpBB 3 forum config
location /forum {
}
# phpBB 3: Deny access to internal phpbb files.
location ~ /(config\.php|common\.php|includes|cache|files|store|images/avatars/upload) {
root /usr/local/www/forum;
deny all;
# deny was ignored before 0.8.40 for connections over IPv6.
# Use internal directive to prohibit access on older versions.
# internal;
}
# phpMyAdmin
location ~ /pma4/(.*\.php)$ {
root /usr/local/www/pma4;
index index.php;
fastcgi_pass localhost:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/www/pma4/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www/pma4;
}
# bugzilla
location ~ ^/bugzilla/(.*\.cgi) {
fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/www/bugzilla/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www/bugzilla;
include fastcgi_params;
}
# php
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
# cgi
location ~ [^/]\.cgi(/|$) {
fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
# phpBB: Deny access to version control system directories.
location ~ /\.svn|/\.git {
deny all;
}
# Original: block access for .htpasswd
location ~ /\.ht {
deny all;
}
}
}
This configuration should help
location /pma4 {
root /usr/local/www;
index index.php;
location ~ .*\.php$ {
fastcgi_pass localhost:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/www/pma4/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www;
}
}
After days smashing my head on the keyboard I finally found the real solution for this problem and I'm sharing here as this thread still have high priority on google search.
As stated on the link : http://www.samundra.com.np/use-phpmyadmin-with-nginx-and-php7/1374
To solve the problem, you should add the following block of code to your nginx default site-available, you will access it with :
sudo nano /etc/nginx/sites-available/default
The block:
# 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;
}
I hope this helps someone one day...