Skip to content

Instantly share code, notes, and snippets.

@inhere
Created March 7, 2018 04:00
Show Gist options
  • Save inhere/994356979a63faf1d7779e6639b33697 to your computer and use it in GitHub Desktop.
Save inhere/994356979a63faf1d7779e6639b33697 to your computer and use it in GitHub Desktop.
swoole 应用的nginx配置参考
server {
listen 80;
server_name www.site.dev site.dev;
root /webroot/static;
index index.html index.htm;
error_log logs/site.dev.error.log;
access_log logs/site.dev.access.log;
##### 第一个必选规则: 匹配首页
location = / {
proxy_pass http://127.0.0.1:9501;
}
##### 第二个必选规则: 处理静态文件请求,这是nginx作为http服务器的强项
# 有两种配置模式,目录匹配或后缀匹配,任选其一或搭配使用
# location ^~ /static/ {
# root /webroot/static/;
# }
location ~* \.(js|css|map|png|jpg|jpeg|gif|ico|ttf|woff2|woff)$ {
expires max;
# root /webroot/static/;
# log_not_found off;
access_log off;
}
##### 通用规则: 上面的都不匹配
location / {
# try_files $uri $uri/;
# proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
proxy_set_header Connection "keep-alive";
# 没有找到文件就转发到 swoole server
# 也可去掉 if. 全部转发到后端server
if (!-e $request_filename){
proxy_pass http://127.0.0.1:9501;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment