I've setup gitlab using the omnibus package on CentOS 7. I'd like to use the gitlab server to host additional websites. I've enabled custom nginx conf by adding the below code to /etc/gitlab/gitlab.rb
nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/*.conf;"
I've also created conf files in /etc/nginc/conf.d. Static HTML files are working but when i try to run php scripts, I'm getting a File not found - 404 error.
Following is the nginx conf for php :
server{
listen 80;
server_name example.com;
root /var/www/vhosts/example;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/gitlab/embedded/html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /opt/gitlab/embedded/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
The following is the error log:
FastCGI sent in stderr: "Primary script unknown" while reading response from upstream, client x.x.x.x, server: example.com, request: "GET / HTTP/1.1", upsteam: "fastcgi://127.0.0.1:9000", host: "example.com"
Maybe your problem comes from your "location ~ .php$" config.
You already fix the first problem with gitlab omnibus by included the right fatscgi_params instead of the default. Now it seems to comes from the location config.
Try the following code for your configuration :
location ~ \.php$ {
#in your case maybe : /opt/gitlab/embedded/html
root [YOUR APP DIRECTORY];
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include /opt/gitlab/embedded/conf/fastcgi_params;
}
This fix works for me on a Debian 8 server.
Hope it could help.
Related
Here's my server block:
server {
listen 80;
server_name localhost;
root /www/html;
index index.php;
location = / {
autoindex on;
index index.php;
try_files $uri $uri/ =404;
}
location ~*\.(css|js|gif|jpe?g|png)$ {
root /www/html/shared;
rewrite ^/releases(.*)$ $1 last;
expires 5m;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Right now, doing this will just spit out a "403 Forbidden" error when I attempt to access "localhost/". However, the page works perfectly fine if I access it directly-- "localhost/index.php". I can't for the life of me figure out why. The error.log doesn't give me any helpful info nor an error code either--only that the page is "forbidden".
Here's the thrown error:
2017/03/29 14:37:35 [error] 11980#8840: *94 directory index of "C:/www/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
This is a windows-based nginx server.
the answer was kind of disappointing to discover, but i'm gonna answer it so if anyone encounters this goofy issue they can fix it.
php was lookng for files with the prefix "/www/html", NOT "/www/html/", as a result when it wanted my index it was trying to load "/www/htmlindex.php" instead of "/www/html/index.php".
you can fix this by doing either
fastcgi_index /index.php;
or adding a / to the end of your root.
Created a virtualhost for symfony application in local system
Here is the nginx config file
server {
listen 80;
server_name local.symfony;
root /home/guest/symfony_demo/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
try_files $uri #rewriteapp;
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# Deny all . files
location ~ /\. {
deny all;
}
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_index app.php;
send_timeout 1800;
fastcgi_read_timeout 1800;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
# Statics
location /(bundles|media) {
access_log off;
expires 30d;
try_files $uri #rewriteapp;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
On load of app in browser its throwing an error
502 Bad Gateway Error:No input file specified.
Error caught from error.log file:
FastCGI sent in stderr: "Unable to open primary script: /home/guest/symfony_demo/web/app.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: local.symfony, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "local.symfony"
Can anyone help me to configure symfony app to app_dev config file.
Any thoughts??
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
This line is the problem. If you remove it, your error disappears. You may then have Opcache problems due to Symfony using symlinks to the current project.
With $realpath_root$fastcgi_script_name, the web server looks at the "real" path for the PHP script based on the root definition in your server block. Nginx must have read permissions to the path for this to work. Your code is in /home/guest/, if nginx is running as "www-data" give it permissions to your directories, or run nginx as the "guest" user (ignoring the security implications of this).
Why don't you start with configuration from official documentation (http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html#nginx) and when that works, you can try to add your custom configuration (caching of sttaic files ...) ?
This should work:
server {
listen 80;
server_name local.symfony;
root /home/guest/symfony_demo/web;
location / {
try_files $uri /app_dev.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
This error happens when nginx is not able to find the php-fpm.sock file.
Can you make sure that the php-fpm.sock file is in the path as mentioned. I had to update fastcgi_pass like below
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
as my php-fpm.sock was there
I installed a portable nginx and php5.3 on windows 7 64bit and I created a sample site needs a url rewrite to run this is the error I always get after my configuration.
2014/11/30 22:56:12 [crit] 2356#3384: *1 GetFileAttributesEx() "D:/nginx/nginx/nginx-1.2.3/html/main.site.dev/index.php/" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 192.168.1.109, server: main.site.web, request: "GET / HTTP/1.1", host: "main.site.web"
here is my current windows nginx server block config:
server {
listen 80;
server_name main.site.web;
root D:/nginx/nginx/nginx-1.2.3/html/main.site.dev;
location / {
try_files $uri index.php$uri$args /index.php$uri$args /index.php;
}
location ~ \.php\/(.+)$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
break;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
location = /php-fpm-ping {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
Notice the "/" at the end of "index.php". What is wrong with the configuration.
Also note that the directory on this window is fully controlled (read & write).
Any suggestion or comments are appreciated. Thank you in advance...
I have created a default CakePHP 2.4 project and created the Nginx configuration as follows but I am getting these errors from Nginx error log. What I have done wrong?
My environment:
Debian (wheezy)
nginx/1.2.1
project directory /var/www/backhaus
The error is:
$ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal redirection cycle while processing "/backhaus", client: xxx.x.x.xx, server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"
Here is my config from ../sites-available/default:
location /backhaus {
root /var/www/backhaus/app/webroot/;
index index.php;
rewrite ^/* /backhaus;
location ~ ^/(.+\.php)$ {
try_files $uri $uri/ =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Your error is this:
$ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal
redirection cycle while processing "/backhaus", client: xxx.x.x.xx,
server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"
And the error clearly states:
…redirection cycle while processing "/backhaus"…
So now, let’s look at your posted Nginx config:
location /backhaus {
root /var/www/backhaus/app/webroot/;
index index.php;
rewrite ^/* /backhaus;
location ~ ^/(.+\.php)$ {
try_files $uri $uri/ =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
It seems like the issue is your location is /backhaus but then you are redirecting any traffic going to /backhaus to /backhaus via this line:
rewrite ^/* /backhaus;
So I would recommend just removing that rewrite line.
Calling "http://test.local/" in the browser returns a "403 Forbidden" error.
Calling "http://test.local/index.php" works well.
If I create a "index.html" file, calling "http://test.local/" shows me the "index.html" file correctly.
So just the "index.php" file doesn't work.
This is my vhost configuration:
server {
listen 80;
server_name test.local;
root /var/www/public;
index index.html index.htm index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
The error.log file contains this error:
2013/12/28 14:00:57 [error] 2854#0: *50 directory index of "/var/www/public/" is forbidden, client: 10.0.2.2, server: test.local, request: "GET / HTTP/1.1", host: "test.local"
Why's that? I've googled a lot now and checked permissions (which are all set to 777) and tried lots of other stuff too, but I don't get it working.
I'm new to nginx so probably I'm just missing something.
Thanks a lot!
Your configuration seems fine, but I think it can be simplified, try this
server {
listen 80;
server_name test.local;
root /var/www/public;
index index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}