2019/11/14 - 常见nginx配置文件

参考语法

配置文件列表

server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com;
    index index.php index.html index.htm;

    server_name example.com;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
}
server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com;
    index index.php index.html index.htm;

    server_name example.com;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        root           C:/wnmp/nginx-1.5.8/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
server {
    listen       80;
    server_name  example.com;

    charset utf8;

    location / {
        proxy_pass       http://127.0.0.1:4000;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

   }
}
server {
    listen 80;
    resolver 8.8.8.8 ipv6=off;
    server_name ~^(.+)\.acs\.xingtingyang\.cn$;
    location /{
        if ($limit_bots = 1) {
            return 403;
        }
        proxy_set_header Accept-Encoding "";
        proxy_set_header Host $1.acs.org;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Referer $1.acs.org;

        proxy_pass http://$1.acs.org;
        proxy_redirect ~^(.+?).acs.org(.+) $1.acs.xingtingyang.cn$2;

        sub_filter acs.org acs.xingtingyang.cn;
        sub_filter_types *;
        sub_filter_once off;
        proxy_cookie_domain .pubs.acs.org .pubs.acs.xingtingyang.cn;                
    }
    access_log logs/acs_access.log;
    error_log logs/acs_error.log;
}