-
Notifications
You must be signed in to change notification settings - Fork 0
Custom NGINX configurations
This is the page I wrote for WNMP configuration; other NGINX installations use the same config options, except that on "production" server you use some different settings than on your local machine (such as IPs and 'hosts').
CONTENTS:
- How to use several different software engines
- Using several local domains
- Force redirect to HTTPS - necessary for phpMyAdmin!
- Including individual config files (recommended for multiple servers / engines)
The default WNMP configuration uses "localhost" as your local domain name (so if you write "http://localhost" in your browser address bar, your server would send its response).
With such configuration, you can access phpMyAdmin (the tool to work with database) at:
"http://localhost/phpmyadmin"
It works because there is "phpmyadmin" folder - in the web root folder of WNMP (the default one is ".\html").
Likewise, you can make another folder in your web root folder (i.e., a new folder aside with the phpmyadmin folder) - for example, "wiki". Put some software in that folder and you could access it by similar address:
"http://localhost/wiki"
This way you can have many software installations, with variuos engines, under one root.
Often such software requires some configuration fine-tuning - so you would need to add several NGINX settings. It can be done by extending 'nginx.conf' file. You could add specific settings in "location" blocks, like this:
location ~ ^/wiki/ {
# Add settings here:
}
Or, it might be cleaner if you define more "server" blocks in your configuration and add settings there:
For example, after the "server" block was closed but before closing "html" block, add another server block, like this:
} # End HTTPS Server
server {
listen 127.0.0.1:80; # IPv4
server_name phpmyadmin;
# Put your specific settings here ("location"s and the like):
}
}
Add two server blocks if you want to work with HTTPS: one block for HTTP, another for HTTPS.
HTTPS is especially necessary for phpMyAdmin, because due to a know bug, after logout from phpMyAdmin, next login attempts may not work, if you connected through HTTP. So make the following config:
server { # HTTP Server
listen 127.0.0.1:80; # IPv4, local host
server_name phpmyadmin; # This is for "phpmyadmin" server/domain
allow 127.0.0.1; # For security, allow access only from your local computer
deny all; # ...disallow from any outside IPs
return 301 https://$server_name$request_uri; # Redirect to HTTPS all requests permanently
}
server { # HTTPS Server
listen 127.0.0.1:443 http2 ssl;
server_name phpmyadmin;
allow 127.0.0.1;
deny all;
ssl_certificate cert.pem;
ssl_certificate_key key.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000" always; # means "no HTTP for files"
## Parametrization using hostname of access and log filenames.
access_log logs/phpmyadmin_access.log;
error_log logs/phpmyadmin_error.log;
root html/phpmyadmin/; # <- Put here your actual root folder if you have changed it
# <- or keep "root html" if you don't change the 'hosts' file; see description in the wiki below
# Put the further configs (such as "location"s) here: ...
}
Insert the server name you have just added (in this case, phpmyadmin) into your system "hosts" file (located in C:\Windows\System32\drivers\etc
), like this:
127.0.0.1 phpmyadmin
Then you could reach it in browser by shorter address: http://phpmyadmin
Otherwise, use "root html" in the config above, instead of "root html/".
You might like to add more local domains - for example, "wiki" (because wiki is a great tool not only for collaboration, but for keeping all personal notes well orgainzed, in one place). Then you add another server block in nginx.config
, and another string in hosts
file, and you could reach your wiki in browser at "http://wiki".
To keep things neat, if you add more domains, place their configs in separate files. For example, create a folder in your WNMP (NGINX) config
folder, let's say "domains". Put there files like
phpmyadmin.conf
wiki.conf
and move those servers declarations to those files.
In nginx.conf, after closing HTTPS server
section, but before closing html
section, add:
include domains\*.conf;
Then all those config files would be included by NGINX automatically.