Nginx - 配置

Nginx - 配置

 

1. 发布静态网站(指定物理地址)

    server {
        listen       8055;
        server_name  localhost;
 
        location / {
            root   D:\IISPublish\stand; # docker: /usr/share/nginx/html  # windows: html\stand
index index.html index.htm; } }

 

2. 发布静态网站(批定IP地址)

复制代码
     server {
         listen       80;
         charset utf-8; 
         server_name  192.168.122.199;# 服务器地址或绑定域名

         location / {# 访问80端口后的所有路径都转发到 proxy_pass 配置的ip中
             proxy_pass http://192.168.122.199:8091;# 配置反向代理的ip地址和端口号 【注:url地址需加上http:// 或 https://
            proxy_redirect default;
         }
     }
复制代码

 

 

3.  发布vue的history模式,配置如下

复制代码
    server {
        listen       8055;
        server_name  localhost;
 
        location / {
            root   html\stand;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        } 
    }
复制代码

 

4. 跨域访问

复制代码
    server {
        listen       8055;
        server_name  localhost;
 
        location / {
            root   html\stand;
            index  index.html index.htm;
             add_header 'Access-Control-Allow-Origin' '*';
             add_header 'Access-Control-Allow-Headers' '*';
             add_header 'Access-Control-Allow-Methods' '*';
             # OPTIONS 直接返回204
             if ($request_method = 'OPTIONS') {
               return 204;
             }
        } 
    }
复制代码

 

 5. 发布二级目录

复制代码
    server {
        listen       8173;
        server_name  localhost;

        location / {
            root   html/dist;
            index  index.html index.htm;
            # try_files $uri $uri/ /index.html; // vue 中的 history 模式使用

            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Headers' '*';
            add_header 'Access-Control-Allow-Methods' '*';
            # OPTIONS 直接返回204
            if ($request_method = 'OPTIONS') {
              return 204;
            } 
        }
    }  
复制代码

 

 文件目录: nginx目录 / html / dist / stand / 内容文件

访问:http://localhost:8073/stand

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

end

 

posted @   无心々菜  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2019-11-13 Beyond Compare 文件对比工具的使用
2019-11-13 SourceTree - 对Git的使用
点击右上角即可分享
微信分享提示