nginx on mac won't run php - nginx

just brewed nginx and php-fpm on my mac (10.9). I used this tutorial:
http://rtcamp.com/tutorials/mac/osx-brew-php-mysql-nginx/
So but when I set up my first "server"-blog in ngix conf, the php-files always will be downloaded, and I don't find any solutions on google.
Here's my conf:
http {
include /usr/local/etc/nginx/sites-enabled/pma.dev.conf;
include /usr/local/Sites/localsites.conf;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
server_name pma.dev;
listen pma.dev:9090;
location / {
root /usr/local/share/phpmyadmin;
index index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
}
}
}

You need a fastcgi_pass directive to tell nginx where your FPM server is running. Eg. fastcgi_pass 127.0.0.1:9000; if you're running it on port 9000.

Related

Wordpress Nginx 404

I have a Wordpress instance running fine, and i have a directory on my server that needs to redirect users to another domain outside the main server using a 302 rule. I add this on my server block and the redirection works fine:
server {
listen 80;
server_name domain.com;
location /lps {
return 302 https://newdomain/$request_uri;
}
}
but when i go to domain.com i got a 404 Not Found error.
I also try without luck.
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
I manage to solve my issue with this:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Main Server Config
server {
listen 80;
server_name localhost;
root /home/site/wwwroot;
index index.html index.htm index.php;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /lps {
return 302 https://newdomain.net/$request_uri;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
My Azure container have FastCGI and had to add the php instruction

nginx - DNS works for www. but not for http://

I have a server that is using ngnix and I have a configuration file:
server {
listen 80;
server_name http://mycoolwebsite.com/;
return 301 http://www.mycoolwebsite.com$request_uri;
}
server {
listen 80;
root /var/www/website/front/public;
index index.php index.html index.htm;
server_name www.mycoolwebsite.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Now when I enter http://www.mycoolwebsite.com the website shows just fine. Whenever I enter http://mycoolwebsite.com I get:
This site can’t be reached | server DNS address could not be found.
What could be the issue here?
Your server name in the first server block should be:
server_name mycoolwebsite.com;
Also, make sure that there is a DNS entry for mycoolwebsite.com that points to your servers IP. This may be separate to the entry for www.mycoolwebsite.com.

Nginx subdomain and domain pointing to the same files in root

I have my-domain.com and prod.my-domain.com and I have created the following configuration settings for both.
prod.my-domain.com
server {
listen 80;
server_name prod.my-domain.com;
location / {
root /usr/share/nginx/html/;
index index.php index.html index.htm;
}
location /prod{
autoindex on;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/index/html/prod/;
}
error_page 500 502 503 504 /50x.html;
location = /50.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
error_page 404 /path/to/404.htm;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
my-domain.com
server{
listen 80;
server_name my-domain.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/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$ {
fastcgi_intercept_errors on;
error_page 404 /path/to/404.htm;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
But, whichever URL I enter takes me where all the files for my-domain.com are stored.
I would like to see the contents for root /usr/share/nginx/index/html/prod/ when I visit
prod.my-domain.com but, it takes me to root /usr/share/nginx/index/html/

NGINX url rewrite on digitalocean

I have problem with url rewrite from example.com to www.example.com on nginx web server. I using new hosting digitalocean.com and still struggling with this...
I will be happy with every opinion.
There is my code:
server {
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
server_name www.example.com;
root /usr/share/nginx/www;
index index.php index.html index.htm;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location / {
try_files $uri $uri/ /index.html;
}
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;
}
}
I have error when I trying to restart nginx server:
Restarting nginx: nginx: [emerg] could not build the server_names_hash, you should
increase server_names_hash_bucket_size: 32
nginx: configuration file /etc/nginx/nginx.conf test failed
The server name is probably too long for the default values.
Modify the /etc/nginx/nginx.conf file by adding the following below the http:
increase server_names_hash_bucket_size: 64
Save this value and test using the -t
nginx -t
Also, watch for any saved default configurations in the sites-available folder which may cause issues.
Try the following:
server {
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
server_name www.example.com;
root /usr/share/nginx/www;
index index.php index.html index.htm;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location / {
try_files $uri $uri/ /index.html;
}
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 gives 504 error after 500 requests

I'm pretty new to using nginx and I'm having an issue where after requesting 500 pages from nginx running locally on my computer I start getting 504 Gateway Timeout error.
My nginx.conf file looks like this
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.php index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 5s;
include fastcgi_params;
}
}
server {
listen 80;
server_name local-testserver;
error_log logs/local-testserver.error.log;
access_log logs/local-testserver.access.log;
keepalive_timeout 1s;
location / {
root C:/Code/PHP/TestServer;
index index.php;
}
location ~ \.php$ {
root C:/Code/PHP/TestServer;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
}
And index.php in TestServer/ just contains
<?php
echo "hi";
?>
I'm testing this with the URLRequest class in AS3, but I actually tried manually sending 500 requests to see if that made a difference and in both cases the 501st request got a 504 error. Restarting the server allows me to make another 500 requests.
Any ideas on what might be happening or how to fix it?
Turns out this isn't an nginx issue at all but a FastCGI one. Setting PHP_FCGI_MAX_REQUESTS=0 as an environment variable before starting FastCGI should allow any number of requests.

Resources