通過(guò)私鑰訪問服務(wù)器 ssh -i 私鑰路徑 root@xxxx
查找nginx路徑:find /|grep nginx.conf
進(jìn)入nginx編輯:
1、全局:vim /etc/nginx/nginx.conf
2、獨(dú)立配置:/etc/nginx/sites-enabled/文件下獨(dú)立配置
sites-enabled
這個(gè)文件夾一般在你需要建立和管理多個(gè)站點(diǎn)的時(shí)候的時(shí)候適應(yīng)植影,可以幫助你更好的組織不同的項(xiàng)目企垦。你需要在這里添加你的nginx配置文案并將他們鏈接至 sites-enabled 目錄下
重啟nginx: /etc/init.d/nginx restart
查看log:tail -f /var/log/nginx/error.log
例如:
server {
listen 8888(端口號(hào));
server_name localhost(域名或者ip);
#配置gzip壓縮訪問
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 5;
gzip_types text/plain application/xml application/x-javascript application/javascript text/javascript text/css image/jpeg image/gif image/png application/json;
root /var/www/html/dist;(項(xiàng)目打包后在服務(wù)器的地址)
location / {
index index.html;
#跨域配置
set $origin '*';
if ($http_origin) {
set $origin "$http_origin";
}
add_header 'Access-Control-Allow-Origin' $origin always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, DELETE, PUT, OPTIONS';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,api-token,content-type,API-TOKEN';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# 找不到配置文件顯示404
try_files $uri $uri/ =404;
}
}