hello , 大家好,我是咖啡汪,又见面了!
今天给大家带来的是niginx 的简易配置文件
主要目的是让新手快速理解 nginx 配置文件中的参数与我们代码配置文件参数的对应关系,以便进行快速有效的部署
1、主前端页面访问地址8091。
2、大屏展示访问地址8098。
2、dist 文件夹位置 D:\nginx-1.18.0\cccc , vue 压缩包 dist.rar直接解压到cccc下。
3、后端地址:https://127.0.0.1:9103/
4、后端访问拼接前缀: prod-api ,前端访问全路径 http://localhost:8091/prod-api/user/information
,
对应后端访问全路径https://127.0.0.1:9103/user/information
(此地址应可以直接用apipost 进行测试才是对的)。
对比下面这段代码,很容易理解对应关系
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://127.0.0.1:9103/;
#proxy_redirect default;
rewrite ^/api/(.*) $1 break;
}
5、咖啡汪提醒:切记,配置文件要在本地改好了,再上传到服务器上去,不然可能不生效!!!,nginx无法使用stop 指令完全关闭,必须用杀死进程的方式才能完全关闭!!!,然后重启就OK了。
nginx.conf 内容如下:
#user root;
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;
client_max_body_size 500m;
client_body_timeout 5m;
proxy_connect_timeout 75s;
proxy_read_timeout 5m;
proxy_send_timeout 5m;
#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;
# upstream cccc{
# server 127.0.0.1:9103 weight=1;
# server 127.0.0.1:9104 weight=2;
# }
server {
listen 8091;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:/nginx-1.18.0/cccc/dist/;
index index.html;
try_files $uri $uri/ /index.html;
#@router;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://127.0.0.1:9103/;
#proxy_redirect default;
rewrite ^/api/(.*) $1 break;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 8098;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:/nginx-1.18.0/cccc/bigscreen/dist/;
index index.html;
try_files $uri $uri/ /index.html;
#@router;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://127.0.0.1:9103/;
#proxy_redirect default;
rewrite ^/api/(.*) $1 break;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# 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;
# }
#}
#server {
# listen 2211 ssl;
# server_name terminal.cccc-thy.com;
# ssl_certificate ../cert/6204252_terminal.cccc-thy.com.pem;
# ssl_certificate_key ../cert/6204252_terminal.cccc-thy.com.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_prefer_server_ciphers on;
# rewrite ^(.*) https://$server_name$1 permanent;
# proxy_redirect http:// https://;
# location / {
# root html; #站点目录。
# index index.html index.htm;
# proxy_pass http://127.0.0.1:2211/;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 非默认端口需要添加$server_port
#proxy_set_header Host $host:$server_port;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header Host $host;
#proxy_set_header X-Forwarded-Host $http_host;
#proxy_set_header X-Forwarded-Port $server_port;
# proxy_redirect off;
# }
#}
}