Nginx 之在windows下的安裝與啟動


一、下載

Nginx運用場景如下:

1、http服務器。Nginx是一個http服務可以獨立提供http服務。可以做網頁靜態服務器。 
2、虛擬主機。可以實現在一台服務器虛擬出多個網站。例如個人網站使用的虛擬主機。 
3、反向代理,負載均衡。當網站的訪問量達到一定程度后,單台服務器不能滿足用戶的請求時,需要用多台服務器集群可以使用nginx做反向代理。並且多台服務器可以平均分擔負載,不會因為某台服務器負載高宕機而某台服務器閑置的情況。

Nginx下載:http://nginx.org/en/download.html

常用命令

nginx -t   驗證(nginx.conf)配置文件是否有語法錯誤
nginx -V   查看Nginx的版本號
start nginx   啟動Nginx (windows下start nginx)
nginx -c /usr/local/nginx/conf/nginx.conf   啟動nginx
nginx -s stop   快速停止或關閉Nginx
nginx -s quit   正常停止或關閉Nginx
nginx -s reload   配置文件修改重裝載命令
nginx -h   查看幫助信息
nginx -s reopen   打開日志文件

 

二、Nginx配置

server {
        listen       8080;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        root   "G:/phpstudy/nginx/html";
        location / {
           index  index.html index.htm index.php l.php;
           autoindex  on;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
        location ~ \.php(.*)$  {
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
    }

三、運行fastcgi

四、運行Nginx

訪問結果如下:

 五、配置中遇到的問題

1、question:Cannot bind/listen socket - [0] No error.    Couldn‘t create FastCGI listen socket on port 127.0.0.1:9000

解決:fastcgi中9000端口被phpstudy占用,所以使用9001端口


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM