Issues with configuring a simple hhvm site (hack-site-example) with ngnix on ubuntu14.04 - hhvm

I followed the instructions here at https://github.com/hhvm/hack-example-site and somehow lost my way when setting up hhvm hack site on ngnix over ubunut 14.04 . Please note that I used the appropriate apt-get repo for 14.04.
However after configuring and trying to access 127.0.0.1:9000 I see an error in the /var/log/hhvm/error.log
FastCGI protocol: received an invalid record
My /etc/ngnix/sites-enabled is as follows
-rw-r--r-- 1 root root 0 Aug 30 22:01 default
lrwxrwxrwx 1 root root 44 Aug 30 22:21 hack-example-site -> /etc/nginx/sites-available/hack-example-site
The contents of /etc/ngnix/sites-available/hack-example-site is as follows:
server {
root ~/hack-example-site/hack-example-site;
index index.php;
location ~ \.php$ {
# If fastcgi backend is on another server disable this.
# Read issue #6 about this
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME ~/hack-example-site/hack-example-site/index.php
fastcgi_param ~/hack-example-site/hack-example-site $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Could someone please help me with this hhvm site running on my local host? Thanks.
Oh and please note the ngnix is installed properly and the server responds to localhost.
The configuration file /etc/nginx/sites-available/hack-example-site below:
server {
root /root/hack-example-site;
index index.php;
server_name localhost;
location ~ \.php$ {
# If fastcgi backend is on another server disable this.
# Read issue #6 about this
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME ~/hack-example-site/hack-example-
site/index.php
fastcgi_param /root/hack-example-site
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
~

I did find a work around to test my hack scripts but not really satisfied with this. I created symbolic link
/etc/ngnix/sites-enabled/default->/etc/ngnix/sites-available/default.
Copied test.php which has simple hello world written in hack to /usr/share/nginx/html. Edit the /etc/nginx/sites-available/default as follows:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
#index index.html index.htm;
index test.php;
# Make site accessible from http://localhost/
server_name localhost;
include hhvm.conf;
Now when I visited localhost, the hackscript was executed and Helloworld was shown.
However I would have liked this to work with /etc/nginx/sites-available/hack-site-example instead of default. Not sure what is going there? Can anyone throw some light?

Related

Apache htaccess rewrite rule works but how do I translate to nginx rewrite directive?

I have a live server running Apache and a dev server running NGINX in docker. I wish to rewrite my sites urls from /index.php?t=123abc to /123abc.
This rule seems to work in .htaccess
RewriteRule ^([0-9a-f]{6})$ index.php?t=$1 [L]
However, I can't get it to translate to an nginx directive. My 'default' site conf is:
server {
listen 80 default_server;
listen 443 ssl;
root /config/www;
index index.html index.htm index.php;
server_name _;
ssl_certificate /config/keys/cert.crt;
ssl_certificate_key /config/keys/cert.key;
client_max_body_size 0;
location / {
rewrite "^/([0-9a-f]{6})/?$" "/index.php?t=$1";
try_files $uri $uri/ =404;
}
autoindex on;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
The /index.php?t=123abc works fine but /123abc gives 404 error.
Please help

nginx serving only / but not any other files

I have two docker containers as below:
nginx ==> working as proxy web server (nginx web server)
dist ==> working as a php-fpm container
And this is my dist.conf:
server {
server_name dist.me.com;
root /var/www/html;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass dist:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/dist_error.log;
access_log /var/log/nginx/dist_access.log;
}
The issue is if I enter dist.me.com, it shows my index.php contents fine. But if I enter dist.me.com/index.php or dist.me.com/index2.php, I get error 404 Not Found.
I tried changing some values of conf file but it did not help me.
Both index.php and index2.php exist in /var/www/html path.
Your existing dist.conf is designed to block URIs ending with .php. The internal directive prevents a location from being directly accessed, and there is also a location which explicitly returns 404 for any URI ending with .php.
You need to change the location rule, remove the internal directive, and delete the location block which follows it.
For example, replace location ~ ^/index\.php(/|$) { ... } and location ~ \.php$ { ... } with the single location block as follows:
location ~ \.php(/|$) {
fastcgi_pass dist:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}

Kubernetes - Nginx - PHP-FPM

I am currently experimenting with Kubernetes and deploying immutable images that contain a PHP webapplication in a load balanced setup.
What I am reading is that both your PHP-FPM (obviously) and your NGINX (this is what puzzles me) need to contain your app (php) code?
Ideally i want to build a custom docker image for php-fpm that includes my app code.
But doing the same for the nginx feels very inefficient?
Since nginx is 'just' a proxy to redirect php requests towards the php-fpm pods, i dont really see the need to have my app code in the nginx container also.
I was reading here:
https://stackoverflow.com/a/44900924/4875368
This seems like a similar setup.
My ideal scenario is having an ingress (nginx) that points to the nginx proxy that then redirects towards the php-fpm (if it is a php request).
If i need to create custom images for both nginx & php-fpm, then it almost feels smarter to create one apache-php image?
All suggestions welcomed!
The nginx config that i am currently looking at looks like this
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/myprojectroot; <==== this is the one confusing me!
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
This one also seems conceptually related, but leaves me wondering on how to procedd nonetheless: https://stackoverflow.com/a/49496411/4875368

How to get content of default nginx configuration file in Docker environment on Ubuntu

Does anyone can point me in the right direction
I'm trying to get the content of default nginx conf file, but I can't find it anywhere in the system.
Tried:
/usr/local/nginx/conf
/etc/nginx
/usr/local/etc/nginx
all patch are not exist
My container is up and running, it shows default nginx successful install page.
Assuming you used the official nginx container, the content is located at etc/nginx/conf.d/default.conf and it's:
root#5b67d1564b45:/# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html 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;
#}
}
But why are you interested in this? Usually what you want to do is to use your own config, not the default one.

asp mvc home root not working with mono, fastcgi and nginx

i have mono 2.6.7 and I'm trying to port an ASP.NET MVC application. i've managed to solve the case sensitivity problem by setting the variable MONO_IOMAP=all . I have still one more problem, my home root isn't working. I get a page not found error (although /home and /home/index work). I'm using nginx and fastcgi. here is my configuration for nginx:
server {
listen 80;
server_name mydomain.com;
access_log /var/log/nginx/mydomain.com.log;
location / {
root /home/ec2-user/www/mydomain-web/;
index index.html index.htm default.aspx Default.aspx;
fastcgi_index Default.aspx;
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
}
This ended up working for me.
server {
listen 80;
server_name mydomain.com;
access_log /var/log/nginx/mydomain.com.log;
location / {
root /home/ec2-user/www/mydomain-web/;
fastcgi_index /;
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
}
I removed the index line completely and changed the fastcgi_index to fastcgi_index /;. Using Mono 3.0.3/ASP.NET MVC3.
Change fastcgi_index Default.aspx;
to
fastcgi_index /Home;

Resources