安装目录
/usr/local/nginx
nginx/下文件列表
client_body_temp fastcgi_temp logs sbin uwsgi_temp conf html proxy_temp scgi_temp vhost
其中vhost是新建的目录,修改nginx配置文件不直接修改conf/nginx.conf文件,而是修改vhost里面文件
这需要nginx.conf配置一下
nginx.conf文件如下
#user nobody;
worker_processes 4;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
#user nobody;
worker_processes 4;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /usr/local/nginx/vhost/*.conf;
}
其中include /usr/local/nginx/vhost/*.conf是添加的配置,修改vhost里面文件,而不是修改nginx.conf
/vhost/abc.conf
nginx 80端口代理静态站点,8000端口代理node接口,abc.conf配置如下
upstream abc {
server 127.0.0.1:8000;
}
server {
listen 80; # 监听端口
server_name ip sina.com; # 站点域名
upstream abc {
server 127.0.0.1:8000;
}
server {
listen 80; # 监听端口
server_name ip sina.com; # 站点域名
server {
listen 80; # 监听端口
server_name ip sina.com; # 站点域名
location / {
try_files $uri $uri/ /index.html; //h5 hash
root /data/web/client;
index index.html index.htm;
#proxy_pass http://abc;
}
location ~* /api/ { //运行api接口跨域访问
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'OPTION, POST, GET';
add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type';
proxy_pass http://abc;
}
}