I have nginx as a webserver with PHP-fpm. I can successfully see my website using http but if I use https I will download the index page and the page will not be shown.
My nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
server_tokens off;
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;
fastcgi_read_timeout 300s;
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;
client_max_body_size 2M;
include /etc/nginx/conf.d/*.conf;
}
server {
listen 443 ssl;
server_name www.domain.net;
root /usr/share/nginx/html;
add_header X-Frame-Options "SAMEORIGIN";
ssl_certificate /etc/letsencrypt/live/www.domain.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.domain.net/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
location / {
index index.php;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
And conf.d/default.conf
server {
listen 80;
server_name www.domain.net;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Your php location tag only exists in the listen 80 server block.
So if the request is sent to the 443 server block, it doesn't handle any php files. You should add the same php block to the 443 server block;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
server_tokens off;
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;
fastcgi_read_timeout 300s;
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;
client_max_body_size 2M;
include /etc/nginx/conf.d/*.conf;
}
server {
listen 443 ssl;
server_name www.domain.net;
root /usr/share/nginx/html;
add_header X-Frame-Options "SAMEORIGIN";
ssl_certificate /etc/letsencrypt/live/www.domain.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.domain.net/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
location / {
index index.php;
}
# NEW
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
## NEW
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Related
First time asking a question here. I have a small virtual machine running Windows 10. I've tried to set up a nginx server with PHP and MySQL Workbench. So far nginx default page works and so does MySQL Workbench, but when I try to edit the nginx.conf file to change the name of the server, it returns the following error:
[error] 7896#480: *7 access forbidden by rule, client: 127.0.0.1, server: web.prueba.local, request: "GET / HTTP/1.1", host: "web.prueba.local"
The insides my nginx.conf file are the following:
#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;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen *:80;
server_name web.prueba.local;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
Edit: This is the working code!
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 www.login.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root C:/trabajos;
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;
}
# 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:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
location /phpmyadmin {
root C:/nginx-1.16.1/nginx-1.16.1;
index index.php;
try_files $uri $uri/ C:/nginx-1.16.1/nginx-1.16.1/phpmyadmin/index.php;
location ~ ^/assets\.*\.php$ {
deny all;
}
location ~ \.php$ {
root C:/nginx-1.16.1/nginx-1.16.1/phpmyadmin;
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
The system is Fedora 25, with Nginx 1.10.2 and PHP 7.0.14 work in CGI Mode.
I using dnf to install phpMyAdmin, the location is /usr/share/phpMyAdmin, so I try to let it work as alias in multi-website.
location /phpmyadmin {
alias /usr/share/phpMyAdmin;
include fastcgi_php.conf;
}
And I add the location into open_basedir.
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/usr/share/phpMyAdmin/:/var/lib/phpMyAdmin/:/etc/phpMyAdmin/:/usr/share/php:/usr/bin/pear:/dev/null:/var/lib/php";
I open the URL and the log show this message:
2016/12/19 17:52:05 [error] 2241#0: *2 FastCGI sent in stderr: "Unable to open primary script: /usr/share/phpMyAdmin/phpmyadmin/index.php (No such file or directory)" while reading response header from upstream, client: 1.1.1.1, server:1.1.1.1 , request: "GET /phpmyadmin/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"
How to make it correct and work? Thank you!
Update:
I think maybe cause by fastcgi_param, in order to solve the blank page problem in PHP fastcgi, I add 2 line into this file.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
nginx.conf:
user nginx nginx;
worker_processes 2;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
use epoll;
worker_connections 2048;
multi_accept on;
}
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;
error_log /var/log/nginx/error.log;
include /etc/nginx/mime.types;
default_type application/octet-stream;
geoip_country /usr/share/GeoIP/GeoIP.dat;
charset UTF-8;
sendfile on;
send_timeout 10;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
server_tokens off;
client_header_timeout 10;
client_max_body_size 64M;
client_body_timeout 10;
client_body_buffer_size 256k;
open_file_cache max=102400 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
types_hash_max_size 4096;
reset_timedout_connection on;
fastcgi_buffers 16 32k;
fastcgi_buffer_size 32k;
fastcgi_intercept_errors on;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
fastcgi_php.conf:
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
website.conf:
server {
listen 443 ssl;
server_name test.domain.com;
root /var/www/site1;
index index.html index.php;
access_log /var/log/site1-access.log combined;
error_log /var/log/site1-error.log warn;
ssl_certificate /etc/nginx/ssl/xxx.crt;
ssl_certificate_key /etc/nginx/ssl/xxx.key;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;
location / {
try_files $uri $uri/ /error.html;
include fastcgi_php.conf;
}
location /phpmyadmin {
alias /usr/share/phpMyAdmin;
include fastcgi_php.conf;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
}
It would work but No such file or directory. Nginx can't find the index.php in /usr/share/phpMyAdmin/phpmyadmin/ because the folder doesn't exists.
You have to edit the alias path of phpmyadmin location (see code snippet how I did). After that go to /usr/share/ path and rename the folder phpMyAdmin to phpmyadmin (lowercase) or use the same notation in Location (e.g. Location /phpMyAdmin)
server {
listen 443 ssl;
server_name test.domain.com;
root /var/www/site1;
index index.html index.php;
# Configure Access and Error Logging
access_log /var/log/site1-access.log combined;
error_log /var/log/site1-error.log warn;
# Configure SSL Certification usage
ssl_certificate /etc/nginx/ssl/xxx.crt;
ssl_certificate_key /etc/nginx/ssl/xxx.key;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
# Add Headers for security purposes
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;
# Define some page rules
location / {
try_files $uri $uri/ /error.html;
include fastcgi_php.conf;
}
location /phpmyadmin {
alias /usr/share;
include fastcgi_php.conf;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
Hi I have a website using wordpress on nginx, I have a 404 Not Found error when accessing to it.
https://kilobytes.fr
I'm using a VPS from ScaleWay and my domain is with CloudFlare (Full SSL (Strict)).
Here is the conf of my website:
server {
listen 80;
root /usr/share/nginx/html;
index index.php;
server_name kilobytes.fr www.kilobytes.fr;
return 301 https://$server_name$request_uri; #Redirection
access_log /var/log/nginx/kilobytes.fr.access_log;
error_log /var/log/nginx/kilobytes.fr.error_log;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php?q=$uri&$args;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
satisfy any;
allow all;
}
}
server {
listen 443 ssl http2;
server_name kilobytes.fr wwww.kilobytes.fr;
ssl_protocols TLSv1.2;
ssl_certificate /etc/letsencrypt/live/kilobytes.fr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/kilobytes.fr/privkey.pem;
## Diffie-Hellman
ssl_ecdh_curve secp384r1;
## Ciphers
ssl_ciphers EECDH+AESGCM:EECDH+AES;
ssl_prefer_server_ciphers on;
# OCSP Stapling
ssl_trusted_certificate /etc/letsencrypt/live/kilobytes.fr/chain.pem;
resolver 80.67.169.12 80.67.169.40 valid=300s;
resolver_timeout 5s;
ssl_stapling on;
ssl_stapling_verify on;
## TLS parameters
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_session_tickets off;
## HSTS
add_header Strict-Transport-Security "max-age=15552000; includeSubdomains; preload";
}
and here is the conf of nginx :
user www-data;
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;
client_max_body_size 100M;
server_tokens off;
include /etc/nginx/sites-enabled/*;
}
My root folder for wordpress is : /usr/share/nginx/html/
I tried a lot of things and nothing worked.. Thanks !
I have spent hours trying to figure this out and read many articles, all of which don't solve the issue.
I keep getting:
*2 connect() failed (111: Connection refused) while connecting to upstream client: 81.xxx.xxx.xxx, server: localhost, request:"GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "52.xxx.xxx.xxx"
I am using Ubuntu 14.4 on an Amazon EC2 micro instance.
nginx.conf:
user www-data;
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;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;
gzip on;
gzip_proxied any;
gzip_types text/plain text/xml text/css application/x-javascript;
gzip_vary on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
open_file_cache max=5000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
server {
listen 80 default_server;
listen 443 ssl;
server_name localhost;
index index.php index.html;
ssl_certificate /etc/ssl/cacert.pem;
ssl_certificate_key /etc/ssl/privkey.pem;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 180m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
ssl_dhparam /etc/ssl/dhparam.pem;
add_header Strict-Transport-Security "max-age=31536000" always;
pagespeed on;
pagespeed RewriteLevel CoreFilters;
pagespeed FileCachePath "/var/cache/pagespeed/";
pagespeed FileCacheSizeKb 102400;
pagespeed FileCacheCleanIntervalMs 3600000;
pagespeed FileCacheInodeLimit 500000;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location / {
root html;
}
#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;
}
# 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$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
}
PHP5 FPM www.conf:
[www]
...
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
#listen = 127.0.0.1:9000
#listen = /tmp/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
...
What is causing this problem?
The nginx.conf below is working, except to the home page that localdomain, redirects to localdomain/index/.
This confing redirects .php to / trailing slash , and phpless url to trailing slash as well.
Obviously though , something is wrong, and all the possible alterations i tried didn't work out. If i remove from the server context the rewrite ^(.*).php$ $1/ permanent; then localdomain is displayed normal without /index/ , but im loosing the .php redirection to trailing slash. Im totally confused and any solution would be greatly appreciated.
user nginx;
worker_processes 4;
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 {
port_in_redirect off;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_bucket_size 64;
client_max_body_size 100m;
server_names_hash_bucket_size 128;
include mime.types;
default_type application/octet-stream;
index index.php index.html index.htm;
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;
#=====================Basic Compression=====================
gzip on;
#gzip_disable "msie6";
#gzip_vary on;
#gzip_proxied any;
#gzip_comp_level 6;
#gzip_buffers 16 8k;
#gzip_http_version 1.1;
#gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
#gzip_static on;
server {
listen 80;
server_name 192.168.10.2;
root /home/html_public;
index index.php index.html;
charset UTF-8;
rewrite ^(.*).php$ $1/ permanent;
location #extensionless-php {
rewrite ^(.*)/$ $1.php last;
rewrite ^(.*)$ $1/ permanent;
}
location / {
try_files $uri $uri/ #extensionless-php;
}
#error_page 404 /404.php;
# permanent server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location /phpMyAdmin {
root /usr/share/;
location ~ ^/phpMyAdmin/(.+\.php)$ {
root /usr/share/;
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpMyAdmin/(.+\ (jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpmyadmin {
rewrite ^/* /phpMyAdmin last;
}
}
}
[Updated Version]
user nginx;
worker_processes 4;
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 {
port_in_redirect off;
server_tokens off;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_bucket_size 64;
client_max_body_size 100m;
server_names_hash_bucket_size 128;
include mime.types;
default_type application/octet-stream;
index index.php index.html index.htm;
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;
#=====================Basic Compression=====================
gzip on;
#gzip_disable "msie6";
#gzip_vary on;
#gzip_proxied any;
#gzip_comp_level 6;
#gzip_buffers 16 8k;
#gzip_http_version 1.1;
#gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
#gzip_static on;
server {
listen 80;
server_name 192.168.10.2;
root /home/html_public;
charset UTF-8;
#access_log logs/host.access.log main;
rewrite ^(.*).php$ $1/ permanent;
location #extensionless-php {
rewrite ^(.*)/$ $1.php last;
return 301 http://$host$request_uri/;
}
location = / {
rewrite ^ /index/;
}
location / {
try_files $uri $uri/ #extensionless-php;
}
#error_page 404 /404.php;
# permanent server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location /phpMyAdmin {
root /usr/share/;
location ~ ^/phpMyAdmin/(.+\.php)$ {
root /usr/share/;
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpmyadmin {
rewrite ^/* /phpMyAdmin last;
}
}
}