Search This Blog

Thursday, June 30, 2016

Nginx and HHVM always return a 404

This because the /etc/nginx/hhvm.conf did not load before the root in vhost.

This is just a quick notice for myself, I will add more example later:

3 fix solutions:

1.move root out of /

server {
listen 443 ssl http2;

root /var/www/default/public;

location / {
index index.html index.htm;
include hhvm.conf;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/default/public;
}


OR:

server {
listen 443 ssl http2;

location / {
root /var/www/default/public;
index index.html index.htm;
include hhvm.conf;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/default/public;
}


2.move hhvm into /

server {
listen 80;
server_name localhost;
root /var/www/html;

include hhvm.conf;
# put hhvm.conf out of location /

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
index index.html index.htm;
}


3.add /var/www replace $doc_root

location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
# I use UNIX socket inside of local port for better security and performance since both Nginx and HHVM on same Server
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}


My /etc/nginx/hhvm.conf file:

location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
# I use UNIX socket inside of local port for better security and performance since both Nginx and HHVM on same Server
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


Reference:

    http://stackoverflow.com/questions/28308099/nginx-and-hhvm-always-return-a-404

No comments:

Post a Comment