Nginx 安装和配置
-
下载Nginx源码: http://nginx.org/en/download.html
-
解压:
tar -zxvf nginx-*.tar.gz
-
配置
cd nginx ./configure --prefix=/usr/local/nginx
-
编译 & 安装
make && make install
如果没有权限, 使用
sudo
-
修改配置文件
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /var/www/html/HelloHBuilder; # 静态资源
index index.html index.htm;
}
location / {
# 服务代理
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}