Rumah  >  Artikel  >  pembangunan bahagian belakang  >  Nginx系列(一安装nginx)

Nginx系列(一安装nginx)

WBOY
WBOYasal
2016-08-08 09:24:06941semak imbas

零. 声明:

以下内容适用于linux环境下,采用源码方式安装

Nginx官网安装指南:http://wiki.nginx.org/InstallChs

一. 下载nginx

1.官网下载:http://nginx.org/en/download.html
2.Git下载:https://github.com/nginx/nginx

二. 必要的依赖库

1.pcre

<code>yum -y <span>install</span> pcre* <span>#nginx rewrite模块</span></code>

2.gcc

<code>yum -y <span>install</span> gcc gcc-c++ <span>#编译nginx</span></code>

三. 安装nginx

1.创建安装文件夹

<code><span>mkdir</span> -p /web/nginx</code>

2.创建运行用户

<code>groupadd www
useradd <span>-r</span><span>-g</span> www www</code>

3.编编译参数

<code><span>.</span>/configure <span>--</span>prefix<span>=</span>/web/nginx <span>--</span><span>with</span><span>-http_stub_status_module</span><span>--</span><span>with</span><span>-pcre</span></code>

配置成功成功后,输出如下内容

4.编译安装

<code><span>make</span> && <span>make</span> install</code>

编译成功后,输出如下内容

四. 启动nginx

<code>/web/nginx/sbin/nginx</code>

3五. 检测是否安装成功

1.开放端口 参考http://longdd.org/index.php/Home/Index/shows/id/158.html

2.访问 127.0.0.1,显示如下界面,则表明nginx安装成功

六. 惯例配置

<code><span>#user  nobody;</span><span>worker_processes</span><span>1</span>;

<span>#error_log  logs/error.log;</span><span>#error_log  logs/error.log  notice;</span><span>error_log</span>  logs/error.log  <span>info</span>;

<span>pid</span>        logs/nginx.pid;


<span>events</span> {
    <span>worker_connections</span><span>1024</span>;
}


<span>http</span> {
    <span>include</span>       mime.types;
    <span>default_type</span>  application/octet-stream;

    <span>log_format</span>  main  <span>'<span>$remote_addr</span> - <span>$remote_user</span> [<span>$time_local</span>] "<span>$request</span>" '</span><span>'<span>$status</span><span>$body_bytes_sent</span> "<span>$http_referer</span>" '</span><span>'"<span>$http_user_agent</span>" "<span>$http_x_forwarded_for</span>"'</span>;

    <span>access_log</span>  logs/access.log  main;

    <span>sendfile</span><span>on</span>;
    <span>#tcp_nopush     on;</span><span>#keepalive_timeout  0;</span><span>keepalive_timeout</span><span>65</span>;

    <span>#gzip  on;</span><span>server</span> {
        <span>listen</span><span>80</span>;
        <span>server_name</span>  localhost;

        <span>#charset koi8-r;</span><span>#access_log  logs/host.access.log  main;</span><span>location</span> / {
            <span>root</span>   html;
            <span>index</span>  index.html index.htm;
        }

        <span>#error_page  404              /404.html;</span><span># redirect server error pages to the static page /50x.html</span><span>#</span><span>error_page</span><span>500</span><span>502</span><span>503</span><span>504</span>  /50x.html;
        <span>location</span> = /50x.html {
            <span>root</span>   html;
        }

        <span># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><span>#</span><span>#location ~ \.php$ {</span><span>#    proxy_pass   http://127.0.0.1;</span><span>#}</span><span># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><span>#</span><span>#location ~ \.php$ {</span><span>#    root           html;</span><span>#    fastcgi_pass   127.0.0.1:9000;</span><span>#    fastcgi_index  index.php;</span><span>#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;</span><span>#    include        fastcgi_params;</span><span>location</span><span>~ \.php$</span> {
        <span>root</span>           /web/www/zhengrui/html/admin;
        <span>fastcgi_pass</span><span>127.0.0.1:9000</span>;
        <span>fastcgi_index</span>  index.php;            
        <span>include</span>        fastcgi_params;
        <span>fastcgi_param</span>   SCRIPT_FILENAME    <span>$document_root</span><span>$fastcgi_script_name</span>;
        <span>fastcgi_param</span>   SCRIPT_NAME        <span>$fastcgi_script_name</span>;
    }

        <span># deny access to .htaccess files, if Apache's document root</span><span># concurs with nginx's one</span><span>#</span><span>#location ~ /\.ht {</span><span>#    deny  all;</span><span>#}</span>
    }


    <span># another virtual host using mix of IP-, name-, and port-based configuration</span><span>#</span><span>#server {</span><span>#    listen       8000;</span><span>#    listen       somename:8080;</span><span>#    server_name  somename  alias  another.alias;</span><span>#    location / {</span><span>#        root   html;</span><span>#        index  index.html index.htm;</span><span>#    }</span><span>#}</span><span># HTTPS server</span><span>#</span><span>#server {</span><span>#    listen       443 ssl;</span><span>#    server_name  localhost;</span><span>#    ssl_certificate      cert.pem;</span><span>#    ssl_certificate_key  cert.key;</span><span>#    ssl_session_cache    shared:SSL:1m;</span><span>#    ssl_session_timeout  5m;</span><span>#    ssl_ciphers  HIGH:!aNULL:!MD5;</span><span>#    ssl_prefer_server_ciphers  on;</span><span>#    location / {</span><span>#        root   html;</span><span>#        index  index.html index.htm;</span><span>#    }</span><span>#}</span>}</code>

以上就介绍了Nginx系列(一安装nginx),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn