Difference between revisions of "Nginx"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) (Created page with "== Password protected == Create a /etc/nginx/.htpasswd <source lang="bash">sudo sh -c "echo -n 'sammy:' >> /etc/nginx/.htpasswd" sudo sh -c "openssl passwd -apr1 >> /etc/ngin...") |
Rafahsolis (talk | contribs) |
||
| Line 1: | Line 1: | ||
| + | == Redirect HTTP to HTTPS == | ||
| + | Create /etc/ngix/sites-available/RedirectHTTPtoHTTPS.conf | ||
| + | <source>server { | ||
| + | listen 80; | ||
| + | rewrite ^(.*) https://$host$1 permanent; | ||
| + | }</source> | ||
| + | enable it with ln -s /etc/ngix/sites-available/RedirectHTTPtoHTTPS.conf /etc/ngix/sites-available/RedirectHTTPtoHTTPS<br /> | ||
| + | Restart Nginx service: sudo service nginx restart | ||
== Password protected == | == Password protected == | ||
Create a /etc/nginx/.htpasswd | Create a /etc/nginx/.htpasswd | ||
Revision as of 08:30, 16 March 2018
Redirect HTTP to HTTPS
Create /etc/ngix/sites-available/RedirectHTTPtoHTTPS.conf
server {
listen 80;
rewrite ^(.*) https://$host$1 permanent;
}enable it with ln -s /etc/ngix/sites-available/RedirectHTTPtoHTTPS.conf /etc/ngix/sites-available/RedirectHTTPtoHTTPS
Restart Nginx service: sudo service nginx restart
Password protected
Create a /etc/nginx/.htpasswd
sudo sh -c "echo -n 'sammy:' >> /etc/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd" # you will be prompt for password
sudo nano /etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}