I am trying to setup ngnix on my vps to serve different stuff e.g
examplesite.com/ (main site)
examplesite.com/pro/ (sub app)
examplesite.com/ad/
I wanted to be able to run different php apps from these directories.
My first task was to get examplesite.com/pro site working but I am having problems.
Please could someone help me ?
I just want to be able to run different things. I am trying install prosper202 on the /pro/ directory.
My default.conf file :
server {
listen 80;
server_name .exmaple.com;
root /usr/share/nginx/html;
client_max_body_size 512M;
# Default location settings
location / {
index index.php;
}
location /pro {
index index.php;
try_files $uri $uri/ pro/index.php?$args;
}
# 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;
}
# Pass the PHP scripts to FastCGI server (locally with unix: param to avoid network overhead)
location ~ \.php$ {
# Prevent Zero-day exploit
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
---------------------------ngnix.conf-------------------------------------
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
My error.log file :
2014/11/06 11:51:41 [error] 3152#0: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 14.16.105.135, server: , request: "GET / HTTP/1.1", host: "IP" 2014/11/06 11:54:39 [error] 3218#0: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 14.176.105.135, server: , request: "GET / HTTP/1.1", host: "IP"
There's a slash missing in your try_files directive.
Replace :
pro/index.php?$args
With :
/pro/index.php$is_args$args.
Related
I'm new to all of this, but can't keep my newly spun micro ec2 server up and running (running wordpress). The PHP-FPM log only has this with logging set to debug.
[17-Oct-2016 15:46:38] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful
My nginx log is continuously filling with errors trying to connect to php5-fpm.sock (hundreds of entries per minute even though there is no one else accessing the site).
2016/10/17 16:32:16 [error] 26389#0: *7298 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 191.96.249.80, server: mysiteredacted.com, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "removed"
After restarting nginx and PHP-FPM the site works for a few minutes before throwing 502 Bad Gateway errors until I restart them both again.
I don't know where to begin with this. Here is my nginx config file:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
port_in_redirect off;
gzip on;
gzip_types text/css text/xml text/javascript application/x-javascript;
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
}
Which also include this file in the /conf.d folder:
server {
## Your website name goes here.
server_name mysiteredacted.com www.mysiteredacted.com;
## Your only path reference.
root /var/www/;
listen 80;
## This should be in your http block and if it is, it's not needed here.
index index.html index.htm index.php;
include conf.d/drop;
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_buffers 8 256k;
fastcgi_buffer_size 128k;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~* \.(css|js|png|jpg|jpeg|gif|ico)$ {
expires 1d;
}
}
The second file has this line:
fastcgi_pass unix:/var/run/php5-fpm.sock;
If that file does not exist it will throw this error.
Check this previous question: How to find my php-fpm.sock?
After hours of searching I finally figured it out.. Turns out it's some sort of brute force attack on /xmlrpc.php as indicated by the thousands of requests of "POST /xmlrpc.php HTTP/1.0".
It's a common WordPress attack. Thanks all.
EDIT: I have noticed the first time you visit it to goes fast, and it also goes fast if you close the browser tab and re-visit it, but if you simply reload or visit it when you have a tab of it open it goes slow, it is really confusing.
today I come with a problem about PHP CGI, I am brand new to nginx and have just installed it, when I noticed I need to start PHP cgi also with it because with IIS it started it for me. so I start php with batch file below but the problem is... slow php files, they load really slowly even if its just html in them.
#ECHO off
echo Starting PHP, please wait!
C:\nginx\php7\php-cgi.exe -b 127.0.0.1:9054 -c C:\nginx\php7\php.ini
ping 127.0.0.1 -n 1>NUL
ping 127.0.0.1 >NUL
EXIT
Am I doing anything wrong with my batch file or nginx config below? (I have 2 configs) the example.com one is the website with a .php file and the nginx (localhost) just has index.html
localhost loads super fast but example.com one loads really slow because of php.
nginx.conf
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root C:\Users\Administrator\Dropbox\websites\local_website;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include vhosts/*.conf;
}
example.com.conf
server {
listen ***.***.**.***:80;
server_name example.com www.example.com;
root C:\Users\Administrator\Dropbox\websites\php_website;
index index.php index.html;
log_not_found off;
charset utf-8;
#access_log logs/example.com-access.log main;
location ~ /\. {allow all;}
location / {
rewrite ^/(|/)$ /index.php?url=$1;
rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?url=$1;
rewrite ^/(.*)\.htm$ /$1.php;
}
location = /favicon.ico {
}
location = /robots.txt {
}
location ~ \.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I had the exactly same problem as you do. try changing your fastcgi_pass.
from this
fastcgi_pass localhost:9054
to this
fastcgi_pass 127.0.0.1:9054
I use laravel 5.1 and nginx/1.8 it's the first time for me with Nginx Server
When i try to access laravel app home page the route working well
get('/', function () {
return view('welcome');
});
But when i try to access any other page
get('/home', function () {
return 'Home Page';
// Or Blade Page
//return view('home');
});
Nginx return
My settings file on /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
#root /usr/share/nginx/html;
root /var/www/nginx/html;
index index.php index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Update
the last result of /var/log/nginx/error.log
#3 /var/www/nginx/html/laravel/vendor/laravel/framework/src/Illuminate
/Foundation/Exceptions/Handler.php(49):
Monolog\Logger->error(Object(Symfo
2016/01/11 22:59:38 [error] 22510#0: *31 directory index of "/var/www/nginx/html/laravel/" is forbidden, client: 127.0.0.1, server: _, request: "GET /laravel/ HTTP/1.1", host: "localhost"
Note:html/laravel -> laravel is the app name
Any Suggestions ?
Root needs to point to the public folder of your laravel installation. If you've installed laravel into /var/www/nginx/html, then it should be:
root /var/www/nginx/html/public
I'm on Windows 8.1 64 bits, PHP 5.6.12 VC11 x64 Thread Safe, nginx 1.9.3. I configured nginx with PHP the way I wanted too (I'm still learning) and I ran it. I opened index.php and it worked, the page displayed correctly. Then I closed the server, opened it again and it stopped working, it sent me the error page instead. This has happened before.
Here's my nginx.conf:
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
include fastcgi.conf;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 2;
#gzip on;
server {
listen 80 default_server;
server_name localhost;
root html;
index index.php;
#charset koi8-r;
access_log logs/host.access.log main;
location / {
try_files $uri $uri/ /index.php;
}
#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;
}
# 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;
#}
location ~* \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME c:/nginx/html/$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;
#}
}
}
Here are the start bat script and js (I run the js):
JS:
var objShell = WScript.CreateObject("WScript.Shell");
var result = objShell.Run("cmd.exe /c start-nginx.bat", 0);
// Give some startup time
WScript.Sleep(3000);
// Navigate to homepage
objShell.Run("http://localhost");
BAT:
#ECHO OFF
c:\nginx\nginx.exe
c:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini
ping 127.0.0.1 -n 1>NUL
echo Starting nginx
echo .
echo .
echo .
ping 127.0.0.1 >NUL
EXIT
Here are the stop bat and js (I run the JS too):
JS:
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c stop-nginx.bat", 0)
BAT:
#ECHO OFF
taskkill /f /IM nginx.exe
taskkill /f /IM php-cgi.exe
EXIT
problem solved
I want to install wordpress osx.
These are what I done.
$ brew install nginx
$ brew install --without-apache --with-fpm --with-mysql php55
download latest wordpress.zip and extract to /var/www/wordpress_test
run php-fpm by php-fpm -g /usr/local/var/run/php-fpm.pid
write nginx config files like this.
/usr/local/etc/nginx/nginx.conf
worker_processes 1;
error_log /usr/local/log/nginx/error.log;
pid /usr/local/var/run/nginx.pid;
events {
worker_connections 256;
}
http {
include /usr/local/etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
#gzip on;
include /usr/local/etc/nginx/site-enabled/*;
}
/usr/local/etc/nginx/site-avaiable/wordpress_test
server {
listen 8080;
server_name localhost;
access_log /usr/local/log/nginx/wordpress_test.access.log;
error_log /usr/local/log/nginx/wordpress_test.error.log;
root /var/www/wordpress_test;
index index.html index.htm index.php;
#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$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
}
create symlink /usr/local/nginx/site-available/wordpress_test to ` usr/local/nginx/site-enabled/wordpress_test
create /var/www/wordpress_test/info.php and write inside it <?php phpinfo(); ?>.
And I can see php info by accessing http://localhost:8080/info.php.
But I get error message when I access http://localhost:8080/index.php.
/usr/local/log/nginx/wordpress_test.error.log doesn't put any message.
and /usr/local/log/nginx/wordpress_test.access.log shows this message.
127.0.0.1 - - [23/Sep/2013:17:21:55 +0900] "GET /index.php HTTP/1.1" 500 537 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36"
How can I solve this problem? What should I check next?
--
I add settings like this from http://codex.wordpress.org/Nginx, then it works.
# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
# Zero-day exploit defense.
# http://forum.nginx.org/read.php?2,88845,page=3
# Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
# Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked.
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_intercept_errors on;
fastcgi_pass php;
}
This seems to be your .htaccess file not working with nginx, Have you converted your wordpress .htaccess file to nginx configuration ?
Please see the url http://winginx.com/htaccess for .htaccess to nginx conf converter.
just add a new location to your /usr/local/etc/nginx/site-avaiable/wordpress_test
location / {
try_files $uri /index.php$request_uri;
}