nginx-config-example.rst
145 lines
| 6.5 KiB
| text/x-rst
|
RstLexer
r1 | Nginx Configuration Example | ||
--------------------------- | |||
Use the following example to configure Nginx as a your web server. | |||
r1263 | |||
r1 | .. code-block:: nginx | ||
r1856 | |||
r1808 | ## rate limiter for certain pages to prevent brute force attacks | ||
r3018 | limit_req_zone $binary_remote_addr zone=req_limit:10m rate=1r/s; | ||
r1 | |||
r1808 | ## custom log format | ||
r636 | log_format log_custom '$remote_addr - $remote_user [$time_local] ' | ||
'"$request" $status $body_bytes_sent ' | |||
'"$http_referer" "$http_user_agent" ' | |||
'$request_time $upstream_response_time $pipe'; | |||
r1263 | ## define upstream (local RhodeCode instance) to connect to | ||
r1 | upstream rc { | ||
r1263 | # Url to running RhodeCode instance. | ||
r3018 | # This is shown as `- URL: <host>` in output from rccontrol status. | ||
r120 | server 127.0.0.1:10002; | ||
r1 | |||
# add more instances for load balancing | |||
r120 | # server 127.0.0.1:10003; | ||
# server 127.0.0.1:10004; | |||
r1 | } | ||
r1263 | ## HTTP to HTTPS rewrite | ||
server { | |||
listen 80; | |||
server_name rhodecode.myserver.com; | |||
r1 | |||
r1263 | if ($http_host = rhodecode.myserver.com) { | ||
rewrite (.*) https://rhodecode.myserver.com$1 permanent; | |||
} | |||
} | |||
## Optional gist alias server, for serving nicer GIST urls. | |||
r1 | server { | ||
listen 443; | |||
server_name gist.myserver.com; | |||
r636 | access_log /var/log/nginx/gist.access.log log_custom; | ||
r1 | error_log /var/log/nginx/gist.error.log; | ||
ssl on; | |||
ssl_certificate gist.rhodecode.myserver.com.crt; | |||
ssl_certificate_key gist.rhodecode.myserver.com.key; | |||
ssl_session_timeout 5m; | |||
r636 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | ||
r1 | ssl_prefer_server_ciphers on; | ||
r636 | 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-SHA256:AES256-SHA256: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'; | ||
r1263 | # strict http prevents from https -> http downgrade | ||
r1 | add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;"; | ||
# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits | |||
r636 | #ssl_dhparam /etc/nginx/ssl/dhparam.pem; | ||
r1 | |||
rewrite ^/(.+)$ https://rhodecode.myserver.com/_admin/gists/$1; | |||
rewrite (.*) https://rhodecode.myserver.com/_admin/gists; | |||
} | |||
r636 | |||
## MAIN SSL enabled server | |||
server { | |||
listen 443 ssl; | |||
server_name rhodecode.myserver.com; | |||
access_log /var/log/nginx/rhodecode.access.log log_custom; | |||
error_log /var/log/nginx/rhodecode.error.log; | |||
r1 | |||
ssl on; | |||
ssl_certificate rhodecode.myserver.com.crt; | |||
ssl_certificate_key rhodecode.myserver.com.key; | |||
ssl_session_timeout 5m; | |||
r636 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | ||
r1 | ssl_prefer_server_ciphers on; | ||
r636 | 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-SHA256:AES256-SHA256: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'; | ||
r1 | |||
r636 | # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits | ||
#ssl_dhparam /etc/nginx/ssl/dhparam.pem; | |||
r1 | |||
r3018 | # example of proxy.conf can be found in our docs. | ||
r636 | include /etc/nginx/proxy.conf; | ||
r3018 | ## uncomment to serve static files by Nginx, recommended for performance | ||
r522 | # location /_static/rhodecode { | ||
r2146 | # gzip on; | ||
# gzip_min_length 500; | |||
# gzip_proxied any; | |||
# gzip_comp_level 4; | |||
# gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; | |||
# gzip_vary on; | |||
# gzip_disable "msie6"; | |||
r3018 | # alias /path/to/.rccontrol/community-1/static; | ||
r457 | # alias /path/to/.rccontrol/enterprise-1/static; | ||
r456 | # } | ||
r120 | |||
r1263 | ## channelstream websocket handling | ||
r477 | location /_channelstream { | ||
rewrite /_channelstream/(.*) /$1 break; | |||
r1263 | |||
r636 | proxy_pass http://127.0.0.1:9800; | ||
r477 | proxy_connect_timeout 10; | ||
proxy_send_timeout 10m; | |||
proxy_read_timeout 10m; | |||
r636 | tcp_nodelay off; | ||
r477 | proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | |||
r636 | proxy_set_header X-Url-Scheme $scheme; | ||
proxy_set_header X-Forwarded-Proto $scheme; | |||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |||
r477 | gzip off; | ||
proxy_http_version 1.1; | |||
proxy_set_header Upgrade $http_upgrade; | |||
proxy_set_header Connection "upgrade"; | |||
} | |||
r3018 | ## rate limit this endpoint to prevent login page brute-force attacks | ||
r1808 | location /_admin/login { | ||
r3018 | limit_req zone=req_limit burst=10 nodelay; | ||
r1808 | try_files $uri @rhode; | ||
} | |||
r120 | location / { | ||
try_files $uri @rhode; | |||
} | |||
r1 | |||
r477 | location @rhode { | ||
proxy_pass http://rc; | |||
} | |||
r636 | |||
r2145 | ## custom 502 error page. Will be displayed while RhodeCode server | ||
## is turned off | |||
r636 | error_page 502 /502.html; | ||
location = /502.html { | |||
r3018 | #root /path/to/.rccontrol/community-1/static; | ||
r636 | root /path/to/.rccontrol/enterprise-1/static; | ||
} | |||
} |