nginx代理实现静态资源访问的示例代码

一   nginx配置本地代理

找到nginx配置文件nginx.conf,配置nginx代理

server{
listen 80;
location / {
alias D:/workspace/sc-multipl-static-web-project/;
index index.html;
}

二   实现域名访问

新增一个找到hosts文件,以管理员身份打开编辑

127.0.0.1 www.chen123.com

nginx配置文件

server{
listen 80;
server_name www.chen123.com;
ssi on;
ssi_silent_errors on;
location / {
alias D:/workspace/sc-multipl-static-web-project/;
index index.html;
}
}

保存配置文件,重启后浏览器输入 localhost:chen123

三   页面预览

再打开nginx配置文件

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream cms_server_pool {
server 127.0.0.1:31001 weight=10;
}
server{
listen 80;
server_name www.xuecheng.com;
ssi on;
ssi_silent_errors on;
location / {
alias D:/workspace/sc-multipl-static-web-project/;
index index.html;
}
location /cms/preview/ {
proxy_pass http://cms_server_pool/cms/preview/;
}
}
}

实现的页面预览接口如下

upstream cms_server_pool {
server 127.0.0.1:31001 weight=10;
}

本地的nginx配置如下

events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream cms_server_pool {
server 127.0.0.1:31001 weight=10;
}
server{
listen 80;
server_name www.xuecheng.com;
ssi on;
ssi_silent_errors on;
location / {
alias D:/workspace/sc-multipl-static-web-project/;
index index.html;
}
location /cms/preview/ {
proxy_pass http://cms_server_pool/cms/preview/;
}
}
}

原创文章,作者:网友投稿,如若转载,请注明出处:https://www.cloudads.cn/archives/4061.html

发表评论

登录后才能评论