nginx簡易部署


Nginx (engine x) 可作為web反向代理服務器。能夠代理外部網絡上的主機,訪問內部網絡

1 首先windows下載nginx :http://nginx.org/download/nginx-1.6.2.tar.gz

2 打開nginx.conf,將需要代理文件路徑寫在root中,端口設為8080:

#user  nobody;
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;  #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; server { listen 8080;//端口號 server_name 127.0.0.1; #location /{ # rewrite ^(.*) https://$server_name$1 permanent;  # } #charset koi8-r; #access_log logs/host.access.log main;  location / { root D:\lanCode\lanSVNTest;//文件路徑 index index.html index.htm; } #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 4433 ssl; server_name localhost; ssl_certificate server.crt; ssl_certificate_key server.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; } } }

3 打開nginx終端輸入指令,或者將nginx 指令寫成批處理文件,在根目錄新建statUp.bat文件寫入:

@echo off
rem 如果啟動前已經啟動nginx並記錄下pid文件,會kill指定進程
nginx.exe -s stop

rem 測試配置文件語法正確性
nginx.exe -t -c conf/nginx.conf

rem 顯示版本信息
nginx.exe -v

rem 按照指定配置去啟動nginx
nginx.exe -c conf/nginx.conf

4 點擊運行starUp.bat,訪問  http://127.0.0.1:8080/ 即可看到反向代理頁面

 需要用用手機連接訪問時,可先查看本機IP192.168.0.105,在手機上訪問

http://192.168.0.105:8080/

nginx常用命令:

nginx -s stop       快速關閉Nginx,可能不保存相關信息,並迅速終止web服務。
nginx -s quit       平穩關閉Nginx,保存相關信息,有安排的結束web服務。
nginx -s reload     因改變了Nginx相關配置,需要重新加載配置而重載。
nginx -s reopen     重新打開日志文件。
nginx -c filename   為 Nginx 指定一個配置文件,來代替缺省的。
nginx -t            不運行,而僅僅測試配置文件。nginx 將檢查配置文件的語法的正確性,並嘗試打開配置文件中所引用到的文件。
nginx -v            顯示 nginx 的版本。
nginx -V            顯示 nginx 的版本,編譯器版本和配置參數。

  


免責聲明!

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



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