您的位置:首页 > 运维架构 > Nginx

PHP环境搭建(8)----nginx安装与配置

2017-05-23 14:12 316 查看
1.# vim /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/6/$basearch/

gpgcheck=0

enabled=1

保存退出

2.#yum install nginx-1.10.3(安装指定版本)

3.#nginx –v(查看版本)

4.#vim /etc/nginx/nginx.conf

user work

worker process数目根据实际cpu来填写

5.#service nginx start|stop|status|restart

配置样例一

nginx.conf

user  work;

worker_processes  16;

error_log  /var/log/nginx/error.log warn;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

}

sdxf.conf

server {

    listen       80;

    server_name  localhost;

    root /home/work/sdxf/server/web;

    index index.php index.html index.htm;

    #charset koi8-r;

    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
try_files $uri $uri/ /index.html;
if (!-e $request_filename){
rewrite  ^/(.*) /index.php;
}
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

    }

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include fastcgi_params;
}

}

配置样例二
nginx.conf

user work;

worker_processes 4;

pid /var/run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;

}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
log_format  main  '$remote_addr $remote_user [$time_local] "$request" $http_host '
'$status $upstream_status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $ssl_protocol $ssl_cipher $upstream_addr '
'$request_time $upstream_response_time';

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

client_max_body_size    128m;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

}

#mail {

# # See sample authentication script at:

# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript


# # auth_http localhost/auth.php;

# # pop3_capabilities "TOP" "USER";

# # imap_capabilities "IMAP4rev1" "UIDPLUS";



# server {

# listen     localhost:110;

# protocol   pop3;

# proxy      on;

# }



# server {

# listen     localhost:143;

# protocol   imap;

# proxy      on;

# }

#}

sdxf-80.conf

server {
listen   80; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        # keepalive_timeout 60;

        # fastcgi_connect_timeout 3000;

        # fastcgi_send_timeout 3000;

        # fastcgi_read_timeout 3000;
root /home/work/sdxf/server/web;
index index.php index.html index.htm;

# Make site accessible from http://localhost/ server_name sdxf.xxxxxxxx.com;

        location / {
proxy_pass http://m.xxxxx.cn:9003; proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";

        }

        #location /data/actiStatic {
#proxy_pass http://m.zjsdxf.cn:9003/data/actiStatic; #proxy_set_header Host $host:80;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Via "nginx";

        #}

location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;    
#}

#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 /usr/share/nginx/www;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#

# 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;

# root html;

# index index.html index.htm;

#

# location / {

# try_files $uri $uri/ =404;

# }

#}

# HTTPS server

#

#server {

# listen 443;

# server_name localhost;

#

# root html;

# index index.html index.htm;

#

# ssl on;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

#

# ssl_session_timeout 5m;

#

# ssl_protocols SSLv3 TLSv1;

# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;

# ssl_prefer_server_ciphers on;

#

# location / {

# try_files $uri $uri/ =404;

# }

#}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx
相关文章推荐