Nginx virtual block on Mac pointing to localhost's index.php - php

I am configuring virtual host to serve .localhost domain on my mac. But when I open "project.localhost" in my browser it shows the same page as, browsing the index of localhost. (ps: I've also configured dnsmasq and /etc/hosts). (trying to serve index.php)
Here is my nginx.conf:
worker_processes 1;
events {
worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
client_max_body_size 50M;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root html;
location / {
# root html;
index index.php 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 html;
}
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include servers/*; }
and here is sites-available:
server {
listen 80;
listen project.localhost:80;
server_name project.localhost;
location / {
root html/project.localhost/public_html;
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
root html/project.localhost/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
and here is dnsmasq.conf:
address=/.localhost/127.0.0.1
and here is /etc/hosts:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 project.localhost www.project.localhost
but when I browse project.localhost in my browser it shows same page as localhost/index.php. What am I doing wrong?

As #Richard mentioned in the comment section I was able to solve the issue by including sites-available/*.conf: include /usr/local/etc/nginx/sites-available/*.conf, just before include server/* into my nginx.conf. Thank you #Richard

Related

Nginx + php-fpm 502 bad gateway only on domain

I have centos server, it's configured with php and nginx, when I restart that time php file is not executing when i type ip address instead of domain address, it's working fine
nginx config for vhost
server {
listen 80;
server_name domainname.com;
rewrite ^ $scheme://www.domainname.com$request_uri? permanent;
}
server {
listen 80;
server_name www.domainname.com;
if ($http_x_forwarded_proto = 'http'){
return 301 https://$host$request_uri;
}
root /home/global/domainname.com;
index index.php index.html index.htm;
access_log /home/global/logs/access.log;
error_log /home/global/logs/error.log;
location = /favicon.ico {
log_not_found off;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
#proxy_ignore_client_abort on;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /home/global/domainname.com$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
You need to add your ip address to your server in your nginx conf if you want to access your server by ip address.
server_name your_ip_address;

phalcon routes not working with nginx in windows.Each time it opens index page

I open any other page it always opens up index page, routes are not properly working for phalcon app. whenever i try to open other page with different route it always open index page. My nginx.conf is below, Please check and suggest for correction.
server {
listen 85;
server_name localhost;
#charset koi8-r;
root abc.example.com;
index index.html index.htm index.php;
#access_log logs/host.access.log main;
autoindex on;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.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_intercept_errors on;
}
#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 html;
}
# general static
location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ {
root abc.example.com;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

Ubuntu 16.04, nginx, phpmyadmin - 502 Bad Gateway

I am using this setting for nginx (default file):
server {
listen 30425;
# Don't want to log accesses.
#access_log /dev/null main;
access_log /var/log/nginx/php.acces_log main;
error_log /var/log/nginx/php.error_log info;
root /usr/share/phpmyadmin;
index index.php index.html index.htm;
error_page 401 403 404 /404.php;
location ~ .*.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}
When I try to access 30425, I am getting 502 Bad Gateway. All other setting are default one (PHP 7).
I had to replace this fastcgi_pass 127.0.0.1:9000;
to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
and then it worked perfectly.
Full code.
server{
listen 80;
index index.html index.htm index.php;
server_name 127.0.0.1;
root /usr/share/phpmyadmin;
location / {
#try_files $uri $uri/ = 404;
autoindex on;
}
location ~\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+);
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_na$
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}

The php file is download instead execute on nginx

I use the Symfony config of Nginx server:
server {
server_name cmf.localhost www.cmf.localhost;
root /mnt/hgfs/www/cmf/web;
error_log /var/log/nginx/cmf.error.log;
access_log /var/log/nginx/cmf.access.log;
# strip app.php/ prefix if it is present
rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;
location = /libs/ckfinder/core/connector/php/connector.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 / {
index app_dev.php app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
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;
}
}
and it work well, but I also need to execute /libs/ckfinder/core/connector/php/connector.php. Now when I try to execute them, it simply download.
How can I config Nginx to executed /libs/ckfinder/core/connector/php/connector.php file?
server {
listen 80;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
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;
}
}

NGINX - Mapping html files to php

I cannot make nginx read php code embedded in .html files for a specific directory (html/test). I run CentOS 6 and have FastCGI installed. I have tried several configurations, but nothing does the job. My nginx.conf looks like this:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name www.domain.com;
rewrite ^(.*) http://domain.com$1 permanent;
}
server {
listen 80;
server_name shop-munk.com *.shop-munk.com;
location / {
root /opt/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/html;
}
location ~ \.php$ {
root opt/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.html$ {
root opt/html/test;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.html;
fastcgi_param SCRIPT_FILENAME /$fastcgi_script_name;
include fastcgi_params;
}
}
}
I was trying to do the same thing and server returned "403 Forbidden" for scripts without .php extension.
Following PHP-FPM configuration fixed the problem:
security.limit_extensions = .php .html

Categories