Nginx基础配置实例配置实现
生活随笔
收集整理的這篇文章主要介紹了
Nginx基础配置实例配置实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
配置的內容如下:
##全局塊 begin## #配置允許運行Nginx工作進程的用戶和用戶組 user www; #配置運行Nginx進程生成的worker進程數 worker_processes 2; #配置Nginx服務器運行對錯誤日志存放的路徑 error_log logs/error.log; #配置Nginx服務器允許時記錄Nginx的master進程的PID文件路徑和名稱 pid logs/nginx.pid; #配置Nginx服務是否以守護進程方法啟動 #daemon on; ##全局塊 end####events塊 begin## events{#設置Nginx網絡連接序列化accept_mutex on;#設置Nginx的worker進程是否可以同時接收多個請求multi_accept on;#設置Nginx的worker進程最大的連接數worker_connections 1024;#設置Nginx使用的事件驅動模型use epoll; } ##events塊 end## ##http塊 start## http{#定義MIME-Typeinclude mime.types;default_type application/octet-stream;#配置允許使用sendfile方式運輸sendfile on;#配置連接超時時間keepalive_timeout 65;#配置請求處理日志格式log_format server1 '===>server1 access log';log_format server2 '===>server2 access log';##server塊 開始##include /home/www/conf.d/*.conf;##server塊 結束## } ##http塊 end##server1.conf
server{#配置監聽端口和主機名稱listen 8081;server_name localhost;#配置請求處理日志存放路徑access_log /home/www/myweb/server1/logs/access.log server1;#配置錯誤頁面error_page 404 /404.html;#配置處理/server1/location1請求的locationlocation /server1/location1{root /home/www/myweb;index index_sr1_location1.html;}#配置處理/server1/location2請求的locationlocation /server1/location2{root /home/www/myweb;index index_sr1_location2.html;}#配置錯誤頁面轉向location = /404.html {root /home/www/myweb;index 404.html;} }server2.conf
server{#配置監聽端口和主機名稱listen 8082;server_name localhost;#配置請求處理日志存放路徑access_log /home/www/myweb/server2/logs/access.log server2;#配置錯誤頁面,對404.html做了定向配置error_page 404 /404.html;#配置處理/server1/location1請求的locationlocation /server2/location1{root /home/www/myweb;index index_sr2_location1.html;}#配置處理/server2/location2請求的locationlocation /server2/location2{root /home/www/myweb;index index_sr2_location2.html;}#配置錯誤頁面轉向location = /404.html {root /home/www/myweb;index 404.html;}}訪問測試:
?
總結
以上是生活随笔為你收集整理的Nginx基础配置实例配置实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx基础配置实例需求分析
- 下一篇: Nginx配置指令之listen