Last active
August 29, 2015 14:07
-
-
Save jordifebrer/6970fc41a23568b193ce to your computer and use it in GitHub Desktop.
Simple example of how to force https, redirect an url and proxy in nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# /etc/nginx/sites-available/my_site.conf | |
# forces https | |
server { | |
listen 80; | |
return 301 https://my_server$request_uri; | |
} | |
server { | |
# https config | |
listen 443 ssl; | |
ssl_certificate /etc/nginx/ssl/my_server/server.crt; | |
ssl_certificate_key /etc/nginx/ssl/my_server/server.key; | |
root /usr/share/nginx/www; | |
index index.html index.htm | |
# redirects root to my main service | |
location / { | |
return 301 /my_main_service/; | |
} | |
# example of a special redirection depending on the user agent | |
location /some_url { | |
if ($http_user_agent ~ (android|iPhone)) { | |
return 301 https://my_mobile_domain$request_uri; | |
} | |
# proxies | |
location /my_main_service/ { | |
# IP address of my main service | |
proxy_pass http://192.168.1.101/; | |
} | |
} | |
# Other commands: | |
# ln -s /etc/nginx/sites-available/my_site.conf /etc/nginx/sites-enabled/my_site.conf | |
# sudo nginx -s reload | |
# sudo service nginx restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment