1. 程式人生 > >Windows平臺下nginx跨域配置

Windows平臺下nginx跨域配置

1)下載地址:

2)啟動

  解壓至d:\nginx,執行nginx.exe(即nginx -c conf\nginx.conf),預設使用80埠,日誌見資料夾D:\nginx\logs

3)使用

4)關閉

  nginx -s stop
5)常用配置

   D:\nginx\conf\nginx.conf,使用自己定義的conf檔案如my.conf,命令為nginx -c conf\my.conf

  常用配置如下: 
  Nginx.conf程式碼 
  http { 
   server { 
   #1.偵聽80埠 
   listen 80; 
   location / { 
   # 2. 預設主頁目錄在nginx安裝目錄的html子目錄。 
   root html; 
   index index.html index.htm; 
   # 3. 沒有索引頁時,羅列檔案和子目錄 
   autoindex on; 
   autoindex_exact_size on; 
   autoindex_localtime on; 
   } 
   # 4.指定虛擬目錄 
   location /tshirt { 
   alias D:\programs\Apache2\htdocs\tshirt; 
   index index.html index.htm; 
   } 
   } 
   # 5.虛擬主機www.emb.info配置 
   server { 
   listen 80; 
   server_name www.emb.info; 
   access_log emb.info/logs/access.log; 
   location / { 
   index index.html; 
   root emb.info/htdocs; 
   } 
   } 
  } 
  

6)檢視nginx程序

  tasklist /fi "imagename eq nginx.exe",如下顯示:
映像名稱                       PID 會話名              會話#       記憶體使用
========================= ======== ================ =========== ============
nginx.exe                     8944 Console                    1      5,128 K
nginx.exe                     6712 Console                    1      5,556 K

7)nginx常用命令

nginx -s stop 強制關閉 
nginx -s quit 安全關閉 
nginx -s reload 改變配置檔案的時候,重啟nginx工作程序,來時配置檔案生效 
nginx -s reopen 開啟日誌檔案

8)其它
  可以通過配置檔案開啟多個nginx工作程序,但同時只有其中一個nginx工作程序在工作,其他的阻塞等待。
  一個nginx工作程序最多同時可以處理1024個連線。
  nginx中需要共享記憶體的cache或者模組無法在windows下正常使用。
  不過,nginx官方正在改進,將來nginx會以服務的方式執行,使用 I/O completion ports代替select方法,使多個工作程序能併發工作。
  要使用nginx配合php-cgi使用,需要修改環境變數,否則,php-cgi執行一定次數就推出,需要重啟,設定PHP_FCGI_MAX_REQUESTS這個變數為0即可。

  以上在win7上通過。 

 8)nginx以windows服務形式啟動

  1.下載微軟兩個工具:

    instsrv.exe srvay.exe

  2.執行命令:

    instsrv Nginxc:/nginx/srvany.exe

  3.配置Nginx的執行引數

  可以直接將配置匯入到登錄檔

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/NGINX/Parameters]
"Application"="D://nginx//nginx.exe"
"AppParameters"=""
"AppDirectory"="D://nginx//"

  注意:windows 下的Nginx 內建的module 很多沒有,用Nginx -V 命令檢視。

跨域示例:

conf內填寫:

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #下面這句話就是允許跨域,我以知乎日報API為例
add_header Access-Control-Allow-Origin *; location / { proxy_pass http://news-at.zhihu.com/api/3/news/latest; } #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://www.quankan.tv; # } # 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; #} }

前臺程式碼示例:

            $.getJSON("http://localhost",
                    function(data){
                console.log(data);
                    }); 

列印結果顯示:

相關推薦

Windows臺下nginx配置

1)下載地址: 2)啟動   解壓至d:\nginx,執行nginx.exe(即nginx -c conf\nginx.conf),預設使用80埠,日誌見資料夾D:\nginx\logs 3)使用 4)關閉   nginx -s stop5)常用配置    D:\nginx\conf\ng

Nginx 配置

res tro 問題 days coo elk max-age user pen 隨著 RESTFul 的流行,就會牽扯到跨域問題,那麽小夥伴有沒有被坑過,高人繞過,有需求的請往下看: location / {  if ($request_method = ‘OPTION

Windows臺下Flutter安裝,配置,初運行。

完成 plugin alpha reac window oct 點擊 and 真機調試 Flutter是什麽?他是谷歌根據Dark語言開源的跨平臺開發依賴。和目前比較火的Reactive Native一樣,一套代碼能夠實現兩個不同平臺的App。那麽為什麽要介紹Flutt

nginx配置(windos走過的坑)

nginx下載地址: http://nginx.org/en/download.html 紅圈區域是穩定版 解壓之後放在資料夾就可以了。 解壓後:  注意:這裡面有個nginx.exe檔案,一般情況下雙擊執行就可以了,但是由於windos部分機型他不支援日誌填寫,執行後可能無法關閉

我也說說Nginx解決前端問題,正確的Nginx配置(後端Nginx CORS配置、CORS設定,後端允許請求)

最近連續兩個朋友問我跨域相關問題,我猜想可能不少朋友也遇到類似問題,我打算寫個部落格聊一下我實際使用的配置, 先說明一下,我並不太瞭解這配置,沒精力去了解太多,但我覺得其中有一些關鍵的小注意點,可能有些初學者不太注意到,導致配置有問題,本文章可能只對新手有點幫助,如果你有好

014.Nginx配置

一 跨域概述 1.1 同源策略 同源策略是一個安全策略。同源,指的是協議,域名,埠相同。瀏覽器處於安全方面的考慮,只允許本域名下的介面互動,不同源的客戶端指令碼,在沒有明確授權的情況下,不能讀寫對方的資源。 同源策略主要是基於如下可能的安全隱患: 使用者訪問www.mybank.com,登入並進行網銀操作,

windowsnginx 配置代理服務,配置多域名,以及最簡單實現配置

Nginx,不用多說啦,大家都熟悉的不能再熟悉了,它是一款輕量級的高效能Web 伺服器/反向代理伺服器及電子郵件(IMAP/POP3)代理伺服器,最近在本地研究將nginx和resin配合使用,使服務效能達到最高,在配置過程中主要涉及到單域名配置代理服務,以及配

windows臺下mysql 8.0 免安裝版配置步驟

免安裝版 utf director my.ini 服務 新建 執行 pro name mysql 8.0 免安裝版配置步驟 新建配置文件 my.ini,內容如下 [mysqld] # set basedir to your installation path basedi

windows下apache 配置

1,首先編輯httpd.conf 找到  #LoadModule headers_module modules/mod_headers.so 去掉# 2,修改以下配置 conf/extra/httpd-ssl      &n

Windows臺下的Redis-Sentinel叢集配置

一、環境介紹 Microsoft Windows 10 企業版 Redis-x64-3.2.100 jedis 2.9.0 Sentinel是一個管理多個redis例項的工具,它可以實現對redis的監控、通知、自動故障轉移。sentinel不斷的檢測red

windows下啟動nginx閃退---(Windows臺下80埠被System佔用解決辦法)

前言: 在專案中用到nginx,啟動時閃退,檢視錯誤日誌,給出的錯誤如下: nginx: [emerg] bind() to 0.0.0.0:80 failed (10013: An attempt was made to access  a socket in a way forb

基礎教程:8、圖解Windows臺下Intellij IDEA安裝與配置

8.1 下載與安裝 (1)開啟官方下載地址 http://www.jetbrains.com/idea/download • 旗艦版(Ultimate) • 社群版(Community) 其中,旗艦版是收費的,社群版則是免費的。兩者的區別就是旗艦版比社群版的功能更為齊全! (2)單

Codeblock 配置C++11編譯環境(windows臺下)

首先去sourceforge上下載 C++11編譯器 GCC4.8.1 windows 64位下 解壓後 在codeblock下設定編譯器 我用的codeblock版本是codebock12.11  他能支援c++11,注意不是支援編譯,是支援開發,C++11的

Go 語言環境配置及編譯器———Windows 臺下

go 語言 windows 下 的編譯器可以去http://code.google.com/p/gomingw/downloads/list 下載 下載解壓配置環境變數 “環境變數”(我的電腦->高階系統設定->環境變數),在系統變數的標籤下,依次新建編輯如下幾

Tomcat / Nginx

https art rep implement maven倉庫 ble param tom .com * tomcat 解決跨域, 1,據說tomcat7.0.40以上才有自帶的CrosFilter,在WEB-INF/web.xml中配置即可: <filter&g

Windows臺下python2和3的兼容問題解決

重啟 pair cap 文件 環境變量 code 命令操作 tro 現在 很多朋友都安裝了python2和3,因為用些庫例如scapy,不是scrapy,python3下面都是錯,那麽怎麽讓python2和3共存呢。 像一般的程序員,達到如下效果 Windows平臺下

Windows臺下PHP7添加Sqlserver擴展

php blog 現在 僅支持 spa reg microsoft 連接 ase 1、7.0.x 7.0.x的擴展下載地址: Microsoft Drivers for PHP for SQL Server https://www.microsoft.com/en-u

webAPI配置

tom method 限制 protocol requested acc bapi access get <httpProtocol> <!--跨域配置開始--> <customHeaders> &

springboot配置

port get example pro har sta 網頁 bean build   關於什麽是跨域的問題,感興趣的同學可以看阮一峰老師的日誌 http://www.ruanyifeng.com/blog/2016/04/cors.html。   下面貼出我在sprin

Windows臺下Elasticsearch同步MySql數據庫

expires pat 插件 date response mob cal ssa mysql 我是用ElasticSearch的版本是elasticsearch-6.3.1 mysql的數據是5.7的,其實這個關系不大。 logstash版本是6.3.1 Elastic