日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx 入门级配置

發(fā)布時(shí)間:2024/4/15 Nginx 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx 入门级配置 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

Ubuntu下安裝Nginx

sudo apt-get install nigx

啟動(dòng)

sudo nginx

在瀏覽器中輸入

http://localhost:80/

出現(xiàn) Welcome to nginx! 安裝成功

重啟

sudo service nginx restart

停止

sudo service nginx stop

靜態(tài)目錄訪問

  • 查找nginx.conf

    sudo find / -name nginx.conf

    結(jié)果:/etc/nginx/nginx.conf

  • 修改默認(rèn)靜態(tài)文件目錄,查看/etc/nginx/nginx.conf; 會(huì)發(fā)現(xiàn)里面有一條include /etc/nginx/sites-enabled/*;, 那去site-enabled目錄看看吧,查看 /etc/nginx/site-enable/default 文件;找到 root /usr/share/nginx/www; , 去這個(gè)目錄看看吧,發(fā)現(xiàn)有個(gè)index.html;那么看看內(nèi)容發(fā)現(xiàn)是’Welcome to nginx!‘

所以修改靜態(tài)文件夾就是修改root 后面那一串自己的數(shù)字就可以了

如果像瀏覽自己的文件目錄

location /a/ {autoindex on; }

負(fù)載均衡配置(后端使用tornado)

  • 先寫一個(gè)tornado的hello.py

    import tornado.ioloopfrom tornado.options import define, optionsimport tornado.webdefine("port", default=8888, help="run on the given port", type=int)tornado.options.parse_command_line()class MainHandler(tornado.web.RequestHandler):def get(self):s = "Hello, world "+str(options.port)self.write(s)application = tornado.web.Application([(r"/test/?", MainHandler),(r"/", MainHandler),])if __name__ == "__main__":application.listen(options.port)tornado.ioloop.IOLoop.instance().start()

    啟動(dòng)web: python hello.py -port=9000

    瀏覽器輸入:http://localhost:9000 就會(huì)看到結(jié)果了

  • 使用nginx負(fù)載均衡,修改nginx.conf參考tornado官網(wǎng)

    user nginx;worker_processes 1;error_log /var/log/nginx/error.log;pid /var/run/nginx.pid;events {worker_connections 1024;use epoll;}http {# Enumerate all the Tornado servers hereupstream frontends {server 127.0.0.1:8000;server 127.0.0.1:8001;server 127.0.0.1:8002;server 127.0.0.1:8003;}include /etc/nginx/mime.types;default_type application/octet-stream;access_log /var/log/nginx/access.log;keepalive_timeout 65;proxy_read_timeout 200;sendfile on;tcp_nopush on;tcp_nodelay on;gzip on;gzip_min_length 1000;gzip_proxied any;gzip_types text/plain text/html text/css text/xmlapplication/x-javascript application/xmlapplication/atom+xml text/javascript;# Only retry if there was a communication error, not a timeout# on the Tornado server (to avoid propagating "queries of death"# to all frontends)proxy_next_upstream error;server {listen 80;# Allow file uploadsclient_max_body_size 50M;location ^~ /static/ {root /var/www;if ($query_string) {expires max;}}location = /favicon.ico {rewrite (.*) /static/favicon.ico;}location = /robots.txt {rewrite (.*) /static/robots.txt;}location / {proxy_pass_header Server;proxy_set_header Host $http_host;proxy_redirect false;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Scheme $scheme;proxy_pass http://frontends;}}}

重啟nginx:

sudo service nginx restart

啟動(dòng)多個(gè)tornado(多個(gè)終端啟動(dòng),或者是后臺(tái)啟動(dòng)):

python hello.py -port=8000 python hello.py -port =8001 python hello.py -port=8002 python hello.py -port =8003

瀏覽器輸入: http://localhost, 發(fā)現(xiàn)沒反應(yīng), 查看nginx錯(cuò)誤日志:/var/log/nginx/error.log出現(xiàn)問題:getpwnam("nginx") failed 解決問題:

sudo adduser --system --no-create-home --disabled-password --group nginx

重啟ngixn, 再試瀏覽器;Ok,刷新瀏覽器,會(huì)發(fā)現(xiàn)每次返回的端口都是不一樣;說明后面的都訪問到了

###總結(jié)

以上的配置都是nginx最常用的入門級(jí)配置;有了這些基礎(chǔ)就可以去找官網(wǎng)找些適用于自己的配置; 其他配置: 參考博客http://blog.s135.com/post/306

轉(zhuǎn)載于:https://my.oschina.net/jiemachina/blog/185484

總結(jié)

以上是生活随笔為你收集整理的Nginx 入门级配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。