- Published on
nginx本地配置代理配置
- Authors
- Name
- KingCwt
- @kingcwtcool

查看nginx在电脑的位置【mac】
sudo nginx -t
Password:
nginx: the configuration file /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful
本机电脑上的nginx配置参考 【/opt/homebrew/etc/nginx/nginx.conf】
#user nobody;
worker_processes 1;
#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;
server {
listen 80;
server_name localhost;
location / {
root /Users/cuihongran/Desktop/wyhl/huaxizhengjuan/web/dist/project-dcp;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/idp {
proxy_pass http://39.101.66.92:8085/api/idp;
proxy_set_header Host $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 404 /index.html;
location = /index.html {
root /Users/cuihongran/Desktop/wyhl/huaxizhengjuan/web/dist/project-dcp;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include servers/*;
}
关闭nginx进程
sudo pkill nginx
启动nginx进程
sudo nginx
获取nginx最新错误日志
tail -n 20 /opt/homebrew/var/log/nginx/error.log
检查语法是否错误
sudo nginx -t
重启
sudo nginx -s reload
查看当前文件是否有访问权限
sudo -u nobody cat /Users/chr/Desktop/wyhl/huaxizhengjuan/web/dist/project-dcp/index.html
赋予权限
sudo chmod -R 755 /Users/chr/Desktop/wyhl/huaxizhengjuan/web/dist/project-dcp