{"id":5484,"date":"2016-11-05T15:56:45","date_gmt":"2016-11-05T07:56:45","guid":{"rendered":"https:\/\/sdeno.com\/?p=5484"},"modified":"2017-07-12T18:06:28","modified_gmt":"2017-07-12T10:06:28","slug":"ubuntu-nginxapache%e7%bb%84%e5%90%88","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=5484","title":{"rendered":"ubuntu 16.04 nginx+apache\u7ec4\u5408 nginx\u53cd\u5411\u4ee3\u7406"},"content":{"rendered":"<p>nginx\u8d1f\u8d23\u5904\u7406\u9759\u6001\u9875\u9762\u5c31\u662fhtml\u6807\u7b7e\uff0capache\u8d1f\u8d23\u5904\u7406php\u811a\u672c\uff0c\u5bf9\u4e8e\u90a3\u4e9b\u8bbf\u95ee\u91cf\u5927\u7684\u7f51\u7ad9\u6765\u8bf4\u8fd9\u6837\u7684\u7ec4\u5408\u662f\u6bd4\u8f83\u9ad8\u6548\u7684\u3002<\/p>\n<p>\u672c\u535a\u5ba2\u5c31\u662f\u4f7f\u7528\u8fd9\u6837\u7684\u7ec4\u5408\u642d\u5efa\u7684\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u914d\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">1,<\/span>\u5728\u6b64\u4e4b\u524d\u9700\u8981\u5b89\u88c5\u4e86lamp\u73af\u5883\uff0c\u53ef\u4ee5\u53c2\u8003<a href=\"https:\/\/sdeno.com\/?p=5280\" target=\"_blank\">https:\/\/sdeno.com\/?p=5280<\/a><\/p>\n<p>\u4e4b\u540e\u4fee\u6539apache\u7684\u9ed8\u8ba4\u7aef\u53e3\u4e3a8080\uff0c\u5728\u8def\u5f84\/etc\/apache2\/ports.conf<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">2,<\/span>\u5b89\u88c5nginx\u670d\u52a1\u7aefsudo apt-get install nginx\uff0cnginx\u8d1f\u8d23\u76d1\u542c80\u7aef\u53e3\u8fc7\u6ee4\u9759\u6001\u8bf7\u6c42\uff0c\u7136\u540e\u52a8\u6001\u8bf7\u6c42\u5373Proxy \u5230Apache \u76848080 \u7aef\u53e3\u3002Proxy \u53cd\u5411\u4ee3\u7406\u7684\u597d\u5904\u662f\u8bbf\u95ee\u7684\u65f6\u5019\uff0c\u59cb\u7ec8\u5c31\u662f80\u7aef\u53e3\uff0c\u6765\u8bbf\u8005\u4e0d\u4f1a\u89c9\u5bdf\u5230\u6709\u4efb\u4f55\u7684\u533a\u522b\u3002(\u6211\u5b89\u88c5\u7684\u7248\u672c\u4e3a<span style=\"color: #000000;\">nginx\/1.10.0<\/span>)<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">3,<\/span>\u914d\u7f6enginx<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210nginx\u4e4b\u540e\u6d4b\u8bd5\u4e0b\u662f\u5426\u6210\u529f\uff0cnginx\u548capache\u4e00\u6837\u9ed8\u8ba4web\u8def\u5f84\u90fd\u662f\/var\/www\/html\uff0c<\/p>\n<p>\u8bbf\u95ee\uff1ahttp:\/\/localhost\/index.nginx-debian.html \u00a0\u770b\u770b\u662f\u5426\u80fd\u6210\u529f\u3002<\/p>\n<p>\u8fdb\u5165\u5230\u76ee\u5f55\u00a0\/etc\/nginx\/sites-available\/ \u00a0\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u540d\u4e3atest\u7684\u6587\u4ef6\u5185\u5bb9\u662f\uff1a<\/p>\n<pre>\/\/\u4ee5\u4e0b\u662f\u5bf9php\u7f51\u7ad9\u7684\u8bbe\u7f6e\r\n\r\nserver {\r\n  listen 80;\r\n  access_log \/var\/www\/html\/nginx.access.log;\r\n  error_log \/var\/www\/html\/nginx.error.log;\r\n  root \/var\/www\/html;\r\n  index index.php index.html;\r\n  server_name www.xgllseo.com xgllseo.com;\r\n  location \\ {\r\n    try_files $uri $uri\/ index.php\/$uri;\r\n  }\r\n  location ~* ^.*\\.php$ {\r\n    if (!-f $request_filename) {\r\n       return 404;\r\n    }\r\n    proxy_set_header X-Real-IP $remote_addr;\r\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n    proxy_set_header Host $host;\r\n    proxy_pass http:\/\/127.0.0.1:8080; (\u524d\u63d0\u8981\u4fdd\u8bc1https:\/\/sdeno.com:8080\/\u8fd9\u6837\u80fd\u6b63\u5e38\u8bbf\u95ee\u5230\uff0c\u4e5f\u5c31\u662f\u8981\u7ed1\u5b9a\u57df\u540d\u548c\u4fee\u6539\u7aef\u53e3)\r\n  }\r\n  location ~ \/\\.(ht|git) {\r\n    deny all;\r\n  }\r\n}\r\n\r\n\r\n\r\n\/\/node.js\u914d\u7f6e\u53ef\u4ee5\u662f\r\nserver{\r\n  listen 80;\r\n  server_name xx.com www.xx.com;\r\n  location \/{\r\n    proxy_pass http:\/\/127.0.0.1:3000;\r\n    proxy_http_version 1.1;\r\n    proxy_set_header Upgrade $http_upgrade;\r\n    proxy_set_header Connection 'upgrade';\r\n    proxy_set_header Host $host;\r\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n    proxy_set_header X-Real-IP $remote_addr;\r\n    proxy_cache_bypass $http_upgrade;  \r\n  }\r\n  access_log \/var\/www\/node\/node.log;\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\/\/\u4e3anode.js\u8bbe\u7f6e\u5185\u5b58\u7f13\u5b58\r\nhttp {\r\n proxy_cache_path <span style=\"color: #ff0000;\">\/var\/cache\/nginx<\/span> levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;\r\n proxy_temp_path <span style=\"color: #ff0000;\">\/var\/tmp<\/span>;\r\n include mime.types;\r\n default_type application\/octet-stream;\r\n sendfile on;\r\n keepalive_timeout 65;\r\n \r\n gzip on;\r\n gzip_comp_level 6;\r\n gzip_vary on;\r\n gzip_min_length 1000;\r\n gzip_proxied any;\r\n gzip_types text\/plain text\/htm text\/css application\/json application\/x-javascript text\/xml application\/xml application\/xml+rss text\/javascript;\r\n gzip_buffers 16 8k;\r\n \r\n ssl_certificate \/root\/www\/Nginx\/1_www.easynode.cn_bundle.crt;\r\n ssl_certificate_key \/root\/www\/Nginx\/2_www.easynode.cn.key;\r\n ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;\r\n ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK;\r\n ssl_prefer_server_ciphers on;\r\n \r\n upstream silly_face_society_upstream {\r\n server <span style=\"color: #ff0000;\">127.0.0.1:3011<\/span>;\r\n #server 127.0.0.1:61338;\r\n keepalive 64;\r\n }\r\n \r\n #server {\r\n # listen 80;\r\n #listen 443 ssl;\r\n \r\n # server_name easynode.cn;\r\n #return 301 $scheme:\/\/www.sillyfacesociety.com$request_uri;\r\n #}\r\n \r\n server {\r\n listen 80;\r\n #listen 443 ssl;\r\n \r\n server_name www.easynode.cn;\r\n \r\n #error_page 502 \/errors\/502.html;\r\n \r\n  #if ($scheme = http) { #80\u7aef\u53e3\u8df3\u8f6c443\r\n  #   return 301 https:\/\/$server_name$request_uri;\r\n  #}\r\n #location ~ ^\/(images\/|img\/|javascript\/|js\/|css\/|stylesheets\/|flash\/|media\/|static\/|robots.txt|humans.txt|favicon.ico) {\r\n #root \/root\/www\/easynode\/public;\r\n #access_log off;\r\n #expires max;\r\n #}\r\n \r\nlocation ~ .*\\.(woff|eot|svg|ttf|favicon.ico|gif|jpg|jpeg|png|bmp|swf)$\r\n{\r\n#expires 30d;\r\nexpires max;\r\nroot \/root\/www\/easynode\/public; #\u91cd\u70b9\r\n}\r\n\r\nlocation ~ .*\\.(js|css)?$\r\n{\r\n#expires 12h;\r\nexpires max;\r\nroot \/root\/www\/easynode\/public; #\u91cd\u70b9\r\n}\r\n \r\n #location \/errors {\r\n # internal;\r\n # alias \/usr\/local\/silly_face_society\/node\/public\/errors;\r\n #}\r\n \r\n location \/ {\r\n proxy_redirect off;\r\n proxy_set_header X-Real-IP $remote_addr;\r\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n proxy_set_header X-Forwarded-Proto $scheme;\r\n proxy_set_header Host $http_host;\r\n proxy_set_header X-NginX-Proxy true;\r\n proxy_set_header Connection \"\";\r\n proxy_http_version 1.1;\r\n proxy_cache one;\r\n proxy_cache_key sfs$request_uri$scheme;\r\n proxy_pass http:\/\/silly_face_society_upstream;\r\n }\r\n }\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u521b\u5efa\u8f6f\u94fe\u63a5<\/p>\n<pre>sudo ln -s \/etc\/nginx\/sites-available\/test \/etc\/nginx\/sites-enabled\/test<\/pre>\n<p>\u8fd9\u65f6\u5019\u5c31\u4f1a\u5728\u00a0sites-enabled\u76ee\u5f55\u4e0b\u770b\u5230\u521a\u521a\u7684test\u914d\u7f6e\u88ab\u542f\u52a8\u4e86<\/p>\n<p>sudo \/etc\/init.d\/nginx restart \u00a0\u91cd\u542fnginx\u5982\u679cOK\u8bf4\u660e\u6ca1\u95ee\u9898<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">4,<\/span>\u914d\u7f6eapache<\/p>\n<p>\u5728\/etc\/apache2\/sites-available\/\u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u4e3atest.conf\u7684\u6587\u4ef6\u5185\u5bb9\u662f\uff1a<\/p>\n<pre>&lt;VirtualHost *:8080&gt;\r\n ServerAdmin webmaster@localhost\r\n DocumentRoot \/var\/www\/html\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>\u521b\u5efa\u8f6f\u94fe\u63a5<\/p>\n<pre>sudo ln -s \/etc\/apache2\/sites-available\/test.conf \/etc\/apache2\/sites-enabled\/test.conf<\/pre>\n<p>\u5728sites-enabled\u76ee\u5f55\u80fd\u770b\u5230\u521a\u521a\u7684test.conf\u8bf4\u660e\u4e5f\u542f\u52a8\u6210\u529f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u63a5\u7740\u6309\u7167\u4e0b\u9762\u987a\u5e8f\u6267\u884c\u4e0b<\/p>\n<pre>sudo a2ensite test\r\nsudo \/etc\/init.d\/apache2 restart\r\nsudo \/etc\/init.d\/apache2 reload<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">5,<\/span>\u5c1d\u8bd5\u4e0b\u662f\u5426\u6210\u529f\uff0c<\/p>\n<p>\u5728\/var\/www\/html\/\u76ee\u5f55\u4e0b\u521b\u5efa1.php\u5185\u5bb9\u4e3a&lt;?php phpinfo();?&gt;\u7684php\u6587\u4ef6\uff0c<\/p>\n<p>\u8bbf\u95ee\uff1ahttp:\/\/localhost\/1.php \u3002<\/p>\n<p>\u5982\u679c\u6210\u529f\u90a3\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.2cto.com\/os\/201202\/119597.html\" target=\"_blank\">http:\/\/www.2cto.com\/os\/201202\/119597.html\u00a0<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>nginx\u8d1f\u8d23\u5904\u7406\u9759\u6001\u9875\u9762\u5c31\u662fhtml\u6807\u7b7e\uff0capache\u8d1f\u8d23\u5904\u7406php\u811a\u672c\uff0c\u5bf9\u4e8e\u90a3\u4e9b\u8bbf\u95ee\u91cf\u5927\u7684\u7f51\u7ad9\u6765\u8bf4\u8fd9\u6837\u7684\u7ec4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[],"class_list":["post-5484","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5484"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5484\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}