nginx.conf 配置
1.配置访问权限
user root;
2.配置返回文件content-type
引入 mime.types
include /ext/nginx/conf/mime.types;
3.配置server
listen 80; //监听端口号
server_name localhost; //本机可以换成域名 www.domain.com
location / 用来监听的路径
alias /home/html; 静态文件路径
root /home/html; 静态文件路径
alias 和 root 的却别
location /web/
alias /home/html;
访问的是 /home/html/web
root /home/html;
访问的是 /home/html;
代理直接使用
location ^~/api{
proxy_pass http://api.server.com
}
完整配置
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /ext/nginx/conf/mime.types;
server {
listen 8080;
server_name localhost;
location / {
alias /home/html;
index index.html;
location ^~/api {
proxy_pass http://api.server.com
}
}
}
}
网友评论