I installed Icinga 1.6.0beta and tried to install it's new web interface using this manual. But it was written for Apache. So I used the following configuration file for nginx to run the interface, but no success. I get directory listing denied in error logs. Any help?
Note: /data/developers/icinga-web symlinked to /usr/local/icinga-web
server {
server_name developers.example.com;
access_log /var/log/nginx/dev.access.log;
error_log /var/log/nginx/dev.error.log;
root /data/developers;
location / {
index index.html index.htm index.php;
}
location /icinga-web/js/ext3/ {
alias /usr/local/icinga-web/lib/ext3/;
}
location /icinga-web/ {
if (!-e $request_filename) {
rewrite ^(/icinga-web)(/.*)$ /icinga-web/index.php?$2 last;
}
}
try_files $uri $uri/ /icinga-web/index.php?$args;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(/icinga-web)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
I ran into the same problem. I had to put the following line:
security.limit_extensions = .php .php5 .cgi
Into the php-fpm pool configuration file.
Of course, after I put that, I now get the following line error:
Parse error: syntax error, unexpected '<' in /usr/local/icinga/sbin/tac.cgi on line 313
But hey, progress!
Ran into almost the same problems years later, better late than never. (I marked the variables you have to set yourself with " % ")
location #icinga {
include fastcgi.conf;
fastcgi_temp_path fastcgi;
fastcgi_pass %YOUR_SOCKET%;
fastcgi_param SCRIPT_NAME /icingaweb2/index.php;
fastcgi_param SCRIPT_FILENAME %ICINGA_WEB_LOCATION%/index.php;
fastcgi_param ICINGAWEB_CONFIGDIR %ICINGA_CONFIG_DIR%;
}
location /icingaweb2 {
alias %ICINGA_WEB_LOCATION%/public;
try_files $uri #icinga;
}
Related
lets say I've a path like:
/var/www/myside/
that path contains two folders... let's say
/static and /manage
I'd like to configure nginx to have an access to:
/static folder on / (eg. http://example.org/)
this folder has some .html files.
/manage folder on /manage (eg. http://example.org/manage) in this case this folder contains Slim's PHP framework code - that means the index.php file is in public subfolder (eg. /var/www/mysite/manage/public/index.php)
I've tried a lot of combinations such as
server {
listen 80;
server_name example.org;
error_log /usr/local/etc/nginx/logs/mysite/error.log;
access_log /usr/local/etc/nginx/logs/mysite/access.log;
root /var/www/mysite;
location /manage {
root $uri/manage/public;
try_files $uri /index.php$is_args$args;
}
location / {
root $uri/static/;
index index.html;
}
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;
}
}
The / works correctly anyway manage doesn't. Am I doing something wrong? Does anybody know what should I change?
Matthew.
To access a path like /var/www/mysite/manage/public with a URI like /manage, you will need to use alias rather than root. See this document for details.
I am assuming that you need to run PHP from both roots, in which case you will need two location ~ \.php blocks, see example below. If you have no PHP within /var/www/mysite/static, you can delete the unused location block.
For example:
server {
listen 80;
server_name example.org;
error_log /usr/local/etc/nginx/logs/mysite/error.log;
access_log /usr/local/etc/nginx/logs/mysite/access.log;
root /var/www/mysite/static;
index index.html;
location / {
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location ^~ /manage {
alias /var/www/mysite/manage/public;
index index.php;
if (!-e $request_filename) { rewrite ^ /manage/index.php last; }
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
}
The ^~ modifier causes the prefix location to take precedence over regular expression locations at the same level. See this document for details.
The alias and try_files directives are not together due to this long standing bug.
Be aware of this caution in the use of the if directive.
I have a Symfony2 application running alongside WordPress - mysite.com/blog routes to my /var/www/mysite/wordpress/ directory and everything else routes to /var/www/mysite/symfony:
server {
listen 80;
server_name mysite.com
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
internal;
}
location /blog {
root /var/www/mysite/wordpress;
rewrite ^/blog/(.+)$ /$1 break;
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
index index.php;
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(?:\/blog)(.+\.php)(.*);
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
Everything works fine, except the WordPress admin (mysite.com/blog/wp-admin/) gives me a 404 error. Visiting mysite.com/blog/wp-admin/index.php works as expected, so it looks like the index index.php line is not working. What could be the issue here?
You should use alias instead of root directive:
location ^~ /blog {
alias /var/www/mysite/wordpress;
index index.php;
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(?:\/blog)(.+\.php)(.*);
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
You need to edit the nginx server Configuration.
# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
# This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)
include fastcgi.conf;
fastcgi_index index.php;
# fastcgi_intercept_errors on;
fastcgi_pass php;
}
More about this here:
http://codex.wordpress.org/Nginx#General_WordPress_rules
So, if you allege that /blog/wp-admin/index.php works, but /blog/wp-admin/ doesn't, perhaps just conditionally append index.php, if need be?
+ rewrite ^/blog/wp-admin(/)?$ /wp-admin/index.php break;
rewrite ^/blog/(.+)$ /$1 break;
So, what do the logs say in regards to your 404? I think this might be related to the fact that the index directive causes "an internal redirect", thus I would not be surprised if your 404 ends up being generated through the / instead of the /blog location.
I saw that many people had problem configuring one nginx server to have multiple symfony2 applications. However, none wanted the same things and had the same problem as me.
What I want to do is to have multiple applications on the same domain. One main application will answer directly to the domain, and the others will be on alias subdirectory.
With a schema :
http://mydomain/ -> main app
http://mydomain/subdir1 -> another app
http://mydomain/subdir2 -> yet another app
I tried by myself to do that and the main app works perfectly. But the subdirectories are most of the time intercepted by the main app, which throws 404. When I try to add app.php in the URL of a subdirectory (like http://mydomain/subdir1/app.php/my/route), the server return 404.
This is what I did until now :
server {
listen 80;
server_name mydomain;
root /server/www/main-app/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
location /subdir1/ {
alias /server/www/other-app1/web;
# try to serve file directly, fallback to app.php
try_files $uri /server/www/other-app1/web/app.php$is_args$args;
# PROD
location ~ ^/other-app1/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
}
Thanks you for your help !
EDIT 26/12/2014 :
For those who did not understand exactly what I want : I want to host multiple symfony2 apps on the same domain name without subdomain. Without subdomain, I must use subdirectory. Before that I tried nginx, I used Apache2 and it was easy to do the trick with Alias.
I did more search and found out that "alias" and "try_files" aren't good friends (see this bug report : http://trac.nginx.org/nginx/ticket/97). So I activated debug mode and did many tests.
Now I almost did it. The main apps no longer intercepts subdirectories and the others apps answer.
But those others apps answer by 404 so I looked in their logs. And I found out that they looked for URL pattern with the subdirectory in it. For instance they searched /subdir1/login instead of /login.
So this is my new configuration :
server {
listen 80;
server_name mydomain;
root /server/www/main-app/web;
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location /subdir1/ {
set $root "/server/www/other-app1/web";
# try to serve file directly, fallback to app.php
try_files $uri #rewriteapp;
}
location / {
index app.php;
set $root "/server/www/main-app/web";
# try to serve file directly, fallback to app.php
try_files $uri #rewriteapp;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
As you can see, the trick was to not use $document_root for the SCRIPT_FILENAME and I created my own instead. I don't know how the symfony2 router search the pattern in the URL, but with my previous configuration (Apache2) I never had this problem. So maybe their is another trick to send the correct path to script app.php.
Thanks you again for your help !
This solved it finally for me (thanks to Claros answer), after million things i tried. Like this, urls like the following work:
/abc/path/to/endpoint
but not /abc/app.php/path/to/endpoint. Config.php and App_dev.php, if in web folder are given back as plain text.
I still try to figure out to get /abc to work (/abc/ works but /abc not). There i get a Symfony exception that route /abc can not be found.
Also some font urls (for bootstrap) are still incorrect but styles, routing etc works.
location /abc {
set $subpath /abc;
set $sfPath /var/www/abc/current/web;
alias $sfPath;
try_files $uri #rewrite;
}
location / {
set $subpath "";
set $sfPath /var/www/def/current/web;
alias $sfPath;
try_files $uri #rewrite;
}
location #rewrite {
rewrite ^(.*)$ $subpath/app.php$1 last;
}
location ~ /app\.php(/|$) {
internal;
include /etc/nginx/fastcgi_params;
fastcgi_index app.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param DOCUMENT_ROOT $sfPath;
fastcgi_param SCRIPT_FILENAME $sfPath/app.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
If you want also the app_dev.php to work in demo environment the best way i found is the following (to have the php block everytime inside the location block):
location /xyz {
set $subpath /xyz;
set $sfPath /var/www/xyz/current/web;
alias $sfPath;
try_files $uri #rewrite;
#Change the match for app_dev.php to work
location ~ /(app|app_dev|config)\.php(/|$) {
#Drop the internal for App_dev.php to work
#internal;
include /etc/nginx/fastcgi_params;
fastcgi_index app.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param DOCUMENT_ROOT $sfPath;
fastcgi_param SCRIPT_FILENAME $sfPath/app.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
After many hours of debugging, I finally solved the problem. This is my final configuration :
server {
listen 80;
server_name mydomain;
root /server/www;
location #rewriteMainApp {
rewrite ^(.*)$ /app.php/$1 last;
}
location #rewriteOtherApp1 {
rewrite ^(.*)$ /subdir1/app.php/$1 last;
}
location /subdir1 {
alias /server/www/other-app1/web;
index app.php;
set $subfolder "other-app1/web";
try_files $uri #rewriteOtherApp1;
}
location / {
root /server/www/main-app/web;
index app.php;
set $subfolder "main-app/web";
try_files $uri #rewriteMainApp;
}
# PROD
location ~ /app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$subfolder/app.php;
}
}
Thanks you all for your help !
Seperate your applications with-in another server tag in your sites-enabled file.
For example:
#Site 1
server {
#Configuration
}
server {
#Configuration 2
}
server {
#Configuration 3
}
Sample configuration:
server {
listen 80;
root /var/www/yourdomain.com/web;
server_name yourdomain.com www.yourdomain.com;
add_header X-UA-Compatible "IE=Edge,chrome=1";
location ~* \.(css|js|gif|jpe?g|png)$ {
expires 1y;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location / {
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/yourdomain.com.error.log;
access_log /var/log/nginx/yourdomain.com.access.log;
}
server {
listen 80;
root /var/www/yourdomain.com/anotherproject/web;
server_name sub1.yourdomain.com www.sub1.yourdomain.com;
add_header X-UA-Compatible "IE=Edge,chrome=1";
location ~* \.(css|js|gif|jpe?g|png)$ {
expires 1y;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location / {
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/sub1.yourdomain.com.error.log;
access_log /var/log/nginx/sub1.yourdomain.com.access.log;
}
I've been struggling with a NGINX configuration. I've set up a development environment (local laptop) with a configuration supporting search engine friendly (SEF) urls, but the same configuration doesn't seem to work on my test server.
local configuration:
server {
server_name example;
root /home/arciitek/git/example/public;
client_max_body_size 500M;
location /collection/ {
try_files $uri $uri/ /collection/index.php$args;
index index.php;
}
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/arciitek/git/example/public/$fastcgi_script_name;
}
}
This works fine. Now on the test environment it looks like this:
{
server_name dev.example.com;
access_log /srv/www/dev.example.com/access.log;
error_log /srv/www/dev.example.com/error.log debug;
root /srv/www/dev.example.com/public;
location /collection/ {
try_files $uri $uri/ /collection/index.php$args;
index index.php;
}
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/dev.example.com/public$fastcgi_script_name;
}
}
On my development environment everything is fine. But on my test environment, when I call a url in my browser with prettyness added : collection/[brand]/[product]. I get the: No input file specified error. Mind you, if I call a url anding with collection/ everyting works as well..
Can anyone help me with this please? if more info is needed, please let me know..
kind regards,
Erik
After frustrating for a long time, I noticed that it was not the configuration that gave me trouble, but the link to sites-enabled...
There you go... *pads himself on the back...
I've used WINGINX to install NGINX, PHP-FPM, MySQL, MongoDB, NodeJS and MemcacheD on my Windows machine.
In the Yii Framework documentation I've found the following host configuration code:
server {
set $host_path "/www/mysite";
access_log /www/mysite/log/access.log main;
server_name mysite;
root $host_path/htdocs;
set $yii_bootstrap "index.php";
charset utf-8;
location / {
index index.html $yii_bootstrap;
try_files $uri $uri/ $yii_bootstrap?$args;
}
location ~ ^/(protected|framework|themes/\w+/views) {
deny all;
}
#avoid processing of calls to unexisting static files by yii
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(.*)$;
#let yii catch the calls to unexising PHP files
set $fsn /$yii_bootstrap;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fsn;
#PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
}
location ~ /\.ht {
deny all;
}
}
Where do I need to store this code?
I've used the hosteditor to create: http://project.loc, and the file: index.php is displayed correctly (located at: /winginx/home/project.loc/pubic_html).
I tried placing the code several directoires:
/winginx/conf
/winginx/conf/vhosts
/winginx/home/project.loc
..but non of it worked.
The Wingix Documentation explains how to do this:
you should create in the winginx\conf\vhosts folder a separate config
file named to domain name plus .conf, e.g. mysite.local.conf.
After the config is added or edited, you should restart Winginx,
double-click start-winginx.exe.
If something goes wrong after these manipulates, please read
winginx\logs\error.log.