Skip to content

Instantly share code, notes, and snippets.

@sepulchre
Created January 18, 2015 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sepulchre/fde24f8f6502afb0e295 to your computer and use it in GitHub Desktop.
Save sepulchre/fde24f8f6502afb0e295 to your computer and use it in GitHub Desktop.
# redirect from non-www to www
server {
listen 80;
server_name demodomain.com;
return 301 $scheme://www.demodomain.com$request_uri;
}
server {
listen 80;
server_name www.demodomain.com;
# limit_conn limit_per_ip 16;
# ssi on;
access_log /home/nginx/domains/demodomain.com/log/access.log ;
error_log /home/nginx/domains/demodomain.com/log/error.log error;
root /home/nginx/domains/demodomain.com/public;
location / {
# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;
# Enables directory listings when index file not found
# autoindex on;
# Shows file listing times as local time
# autoindex_localtime on;
# Enable for vBulletin usage WITHOUT vbSEO installed
# try_files $uri $uri/ /index.php;
}
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
}
# redirect from non-www to www
# uncomment, save file and restart Nginx to enable
#server {
# listen 80;
# server_name mydomain.com;
# return 301 $scheme://www.mydomain.com$request_uri;
# }
server {
server_name mydomain.com www.mydomain.com;
# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;
# limit_conn limit_per_ip 16;
# ssi on;
access_log /home/nginx/domains/mydomain.com/log/access.log combined buffer=32k;
error_log /home/nginx/domains/mydomain.com/log/error.log;
root /home/nginx/domains/mydomain.com/public;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$uri&$args;
# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;
# Enables directory listings when index file not found
#autoindex on;
# Shows file listing times as local time
#autoindex_localtime on;
# Enable for vBulletin usage WITHOUT vbSEO installed
#try_files $uri $uri/ /index.php;
}
location /internal_data/ {
internal;
allow 127.0.0.1;
deny all;
}
location /library/ {
internal;
allow 127.0.0.1;
deny all;
}
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
}
# https SSL SPDY phpmyadmin
server {
listen 443 ssl spdy;
server_name server.mydomain.com;
root html;
keepalive_timeout 1800;
client_body_buffer_size 256k;
client_body_timeout 1800s;
client_header_buffer_size 256k;
## how long a connection has to complete sending
## it's headers for request to be processed
client_header_timeout 60s;
client_max_body_size 512m;
connection_pool_size 512;
directio 512m;
ignore_invalid_headers on;
large_client_header_buffers 8 256k;
ssl_certificate /usr/local/nginx/conf/ssl/server.mydomain.com.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/server.mydomain.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# mozilla recommended
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!CAMELLIA;
ssl_prefer_server_ciphers on;
add_header Alternate-Protocol 443:npn-spdy/3;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
add_header X-Frame-Options SAMEORIGIN;
spdy_headers_comp 6;
ssl_buffer_size 1400;
ssl_session_tickets on;
# limit_conn limit_per_ip 16;
# ssi on;
access_log /var/log/nginx/localhost_ssl.access.log main buffer=32k;
error_log /var/log/nginx/localhost_ssl.error.log error;
# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;
location / {
}
include /usr/local/nginx/conf/phpmyadmin_https.conf;
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
include /usr/local/nginx/conf/errorpage.conf;
}
useradd: user 'phpmyadmin' already exists
---------------------------------------------------------------
Create User: phpmyadmin
uid=503(phpmyadmin) gid=503(phpmyadmin) groups=503(phpmyadmin),501(nginx)
---------------------------------------------------------------

---------------------------------------------------------------
Installing phpmyadmin from official git repository...
---------------------------------------------------------------
This process can take some time depending on
speed of the repository and your server...

Initialized empty Git repository in /usr/local/nginx/html/5688_mysqladmin23352/.git/
Switched to a new branch 'STABLE'
Branch STABLE set up to track remote branch STABLE from origin.
---------------------------------------------------------------
Setup /usr/local/nginx/conf/phpmyadmin.conf ...
---------------------------------------------------------------
---------------------------------------------------------------
Create phpmyadmin htaccess user/pass...
python /usr/local/nginx/conf/htpasswd.py -c -b /usr/local/nginx/conf/htpassphpmyadmin adminsr896O1Crrc= kHtKkcWclIScbaD5al8RhetP9nI=
---------------------------------------------------------------

\cp -af /usr/local/nginx/conf/php.conf /usr/local/nginx/conf/php_5688_mysqladmin23352.conf
---------------------------------------------------------------
server {
# listen 80;
listen 80 default_server backlog=256;
server_name server.mywebsite.com;
root html;
access_log /var/log/nginx/localhost.access.log main buffer=32k;
error_log /var/log/nginx/localhost.error.log error;
# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;
# limit_conn limit_per_ip 16;
# ssi on;
location / {
# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;
# Enables directory listings when index file not found
# autoindex on;
# Shows file listing times as local time
# autoindex_localtime on;
# Enable for vBulletin usage WITHOUT vbSEO installed
# try_files $uri $uri/ /index.php;
}
# example nginx-http-concat
# /csstest/??one.css,two.css
#location /csstest {
#concat on;
#concat_max_files 20;
#}
include /usr/local/nginx/conf/phpmyadmin.conf;
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/cinfo.conf;
include /usr/local/nginx/conf/php.conf;
#include /usr/local/nginx/conf/phpstatus.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
}---------------------------------------------------------------
NON-STATIC IP configuration
---------------------------------------------------------------
cat /usr/local/nginx/conf/phpmyadmin.conf
---------------------------------------------------------------
location ^~ /5688_mysqladmin23352/ {
rewrite ^/(.*) https://server.mywebsite.com/$1 permanent;
}
---------------------------------------------------------------
cat /usr/local/nginx/conf/phpmyadmin_https.conf
---------------------------------------------------------------
location ^~ /5688_mysqladmin23352/ {
#try_files $uri $uri/ /5688_mysqladmin23352/index.php?$args;
include /usr/local/nginx/conf/php_5688_mysqladmin23352.conf;
auth_basic "Private Access";
auth_basic_user_file /usr/local/nginx/conf/htpassphpmyadmin;
#allow 127.0.0.1;
#allow 79.225.41.141;
#deny all;
}
---------------------------------------------------------------

touch /usr/local/nginx/conf/phpfpmd/phpfpm_myadmin.conf

Dynamically set PHP memory_limit based on available system memory...

Total Mem: 6144 MB
Real Free Mem: 5805 MB
Mem Limit: 2580 MB

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] open() "/home/nginx/domains/demodomain.com/log/access.log" failed (2: No such file or directory)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
Gracefully shutting down php-fpm . done
Starting php-fpm done
---------------------------------------------------------------
SSL Vhost Setup...
---------------------------------------------------------------

---------------------------------------------------------------
Generating self signed SSL certificate...
Just hit enter at each of the prompts
---------------------------------------------------------------

Generating RSA private key, 1024 bit long modulus
............++++++
...............................++++++
e is 65537 (0x10001)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:State or Province Name (full name) []:Locality Name (eg, city) [Default City]:Organization Name (eg, company) [Default Company Ltd]:Organizational Unit Name (eg, section) []:Common Name (eg, your name or your server's hostname) []:Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:An optional company name []:Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd
Getting Private key
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] open() "/home/nginx/domains/demodomain.com/log/access.log" failed (2: No such file or directory)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
Gracefully shutting down php-fpm . done
Starting php-fpm done
chmod: cannot access `/var/log/nginx/localhost_ssl.access.log': No such file or directory
chmod: cannot access `/var/log/nginx/localhost_ssl.error.log': No such file or directory
---------------------------------------------------------------
Create update script:
/root/tools/phpmyadmin_update.sh
---------------------------------------------------------------
---------------------------------------------------------------
Create uninstall script:
/root/tools/phpmyadmin_uninstall.sh
---------------------------------------------------------------

---------------------------------------------------------------
Password protected 5688_mysqladmin23352
at path /usr/local/nginx/html/5688_mysqladmin23352
config.inc.php at: /usr/local/nginx/html/5688_mysqladmin23352/config.inc.php
 WEB url:

 https://server.mywebsite.com/5688_mysqladmin23352

Login with your MySQL root username / password
---------------------------------------------------------------

phpmyadmin htaccess login details:
Username: adminsr896O1Crrc=
Password: kHtKkcWclIScbaD5al8RhetP9nI=
Allowed IP address: 79.225.41.141

---------------------------------------------------------------
phpmyadmin update script at: /root/tools/phpmyadmin_update.sh
Add your own cron job to automatically run the update script i.e.

 15 01 * * * /root/tools/phpmyadmin_update.sh

---------------------------------------------------------------
phpmyadmin uninstall script at: /root/tools/phpmyadmin_uninstall.sh

 /root/tools/phpmyadmin_uninstall.sh

---------------------------------------------------------------
SSL vhost: /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
php-fpm includes: /usr/local/nginx/conf/php_5688_mysqladmin23352.conf
php-fpm pool conf: /usr/local/nginx/conf/phpfpmd/phpfpm_myadmin.conf
dedicated php-fpm pool user: phpmyadmin
dedicated php-fpm pool group: nginx
dedicated php error log: /var/log/php_myadmin_error.log
---------------------------------------------------------------
SSL vhost access log: /var/log/nginx/localhost_ssl.access.log
SSL vhost error log: /var/log/nginx/localhost_ssl.error.log
---------------------------------------------------------------

Total phpmyadmin Install Time: 274.333721226 seconds
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# keepalive_timeout 30;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
#openssl <1.0.1
#ssl_protocols SSLv3 TLSv1;
#openssl >=1.0.1
#ssl_protocols SSLv3 TLSv1.1 TLSv1.2;
##
# ssl_session_cache shared:SSL:10m;
# ssl_session_timeout 10m;
## http://www.openssl.org/docs/apps/ciphers.html
# ssl_ciphers RC4:HIGH:!aNULL:!MD5:!kEDH;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# }
#include /usr/local/nginx/conf/staticfiles.conf;
#include /usr/local/nginx/conf/php.conf;
#include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
#}
server {
# listen 80;
listen 80 default_server backlog=256;
server_name server.mywebsite.com;
root html;
access_log /var/log/nginx/localhost.access.log main buffer=32k;
error_log /var/log/nginx/localhost.error.log error;
# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;
# limit_conn limit_per_ip 16;
# ssi on;
location / {
# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;
# Enables directory listings when index file not found
# autoindex on;
# Shows file listing times as local time
# autoindex_localtime on;
# Enable for vBulletin usage WITHOUT vbSEO installed
# try_files $uri $uri/ /index.php;
}
# example nginx-http-concat
# /csstest/??one.css,two.css
#location /csstest {
#concat on;
#concat_max_files 20;
#}
include /usr/local/nginx/conf/phpmyadmin.conf;
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/cinfo.conf;
include /usr/local/nginx/conf/php.conf;
#include /usr/local/nginx/conf/phpstatus.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment