Linux:nginx配置示例

支持PHP

在Ubuntu下安装LEMP

配置文件

一般放在/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;

}

转载于:https://my.oschina.net/letiantian/blog/630573

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值