支持PHP
配置文件
一般放在/etc/nginx/sites-available
中,若要启用某配置文件,需要将其链接到/etc/nginx/sites-enabled/
。
静态网站
需要将域名static-site.domain.com指向主机的IP。
/etc/nginx/sites-enabled/static-site.conf:
server { listen 80; ## listen for ipv4; this line is default and implied listen [::]:80 default ipv6only=on; ## listen for ipv6 server_name static-site.domain.com; root //path/to/static-site/; location ~.*\.(ico|css|js|gif|jpe?g|png)$ { expires 2d; } location / { index index.html index.htm; error_page 404 /error.html; expires 2h; }}
Ghost博客
/etc/nginx/sites-enabled/ghost.conf:
配置Ghost监听本地的2368端口。
upstream ghost { server 127.0.0.1:2368;}server { listen 80; server_name ghost.domain.com; server_name_in_redirect off; access_log off; error_log /path/to/ghost/nginx-error.log; # Allow file uploads client_max_body_size 1M; proxy_read_timeout 10; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://ghost; }}
通过IP访问时候自动转到某域名
如从 122.122.122.122 自动转到 www.domain.com 。
server { listen 80; ## listen for ipv4; this line is default and implied listen [::]:80 default ipv6only=on; ## listen for ipv6 server_name 122.122.122.122; return 301 $scheme://www.domain.com$request_uri;}