Jump to content



Photo

How to setup Nginx + fastcgi + SSL on Ubuntu/Debian

Tutorial

  • Please log in to reply
2 replies to this topic

#1 Conner

Conner

    Haphost Support Staff

  • Moderators
  • 140 posts
  • LocationSouthport, UK

Posted 05 August 2014 - 04:21 PM

[Original Post by: samip]

 

Hello all,

Today I'll telling you how to setup semi-secure nginx web server with fastcgi and add SSL to it.

Here it goes:

1. Log in to your server as root (Superuser)
2. Execute these commands on terminal or use an script made by me. (Command to grab the script: wget https://sami-mantysa...nload/script.sh && chmod +x script.sh )
 

Code:
apt-get update
apt-get install nginx php5-fpm

3. Setup php5-fpm to listen on TCP port insted of unix style socket:

Code:
nano /etc/php5/fpm/pool.d/www.conf

Press ctrl + w and type: listen =
Make sure it shows it as:

Code:
listen = 127.0.0.1:9000

4. Create self signed cert for ssl.

Code:
cd /etc/nginx/
mkdir p conf/certs
cd conf/certs
openssl req -nodes -x509 -newkey rsa:4096 -keyout self-signed.key -out self-signed.crt5. Nginx setup begins. Type these commands:
Code:mkdir /var/www
cd /etc/nginx/sites-available/
nano vhost-with-fastcgi-and-sslThis is the config for the vhost:
Code:server {
listen 443 ssl; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6


# root /usr/share/nginx/www; ## Nginx default document root
root /var/www;
index index.html index.htm;


#### START SSL Configuration ####
ssl on;
ssl_certificate /etc/nginx/conf/certs/self-signed.crt;
ssl_certificate_key /etc/nginx/conf/certs/self-signed.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;


#### END SSL Configuration ####


access_log logs/www_vhost_ssl_fastcgi_access.log;
error_log logs/www_vhost_ssl_fastcgi_error.log;




location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}






#error_page 404 /404.html;


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}


# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one


location ~ /\.ht {
deny all;
}
}

6. Make symbolic link in sites-enabled folder to it. Commands to do so:

Code:
cd /etc/nginx/sites-enabled/
ln -s ../sites-available/vhost-with-fastcgi-and-ssl vhost-with-fastcgi-and-ssl

7. Make logs folder and create and index page. Commands:

Code:
cd /etc/nginx/
mkdir logs
cd /var/www/
nano index.html
chown -R www-data:www-data /var/www/

Example index.html file:

HTML Code:
<html><head> <title>It Works</title></head>
<body><article> <p> <center> It Works! </center> </p></article></body></html>

8. If you want semi-secure server paste this to nginx.conf file:

Code:
user www-data;
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;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

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

9. Restart services. Commands below:

Code:
service nginx restart && service php5-fpm restart

Testing phease:

https://your.server.ip

If it worked then well done! You have it correctly configured.

Please leave feedback on this.


  • cloudfastservers and cloudfast like this

logo.png

PRCTBpj.pngjkrTvsD.pngCxmhW0x.pngmu8GezS.png

jwY2Lj6.png aywcg7Z.png sIQJdfx.png 1y1jJaf.png CD6em6I.png


#2 Omega™

Omega™

    Newbie

  • Members
  • Pip
  • 4 posts
  • LocationItaly

Posted 30 October 2014 - 10:49 PM

The link https://sami-mantysa...nload/script.sh is not working



#3 cloudfastservers

cloudfastservers

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 12 November 2014 - 03:57 AM

tanks for this great tutorial on WHM

Nginx Admin Install instruction:

cd /usr/local/src

wget http://nginxcp.com/l...nginxadmin.tar 

tar xf nginxadmin.tar

cd publicnginx

./nginxinstaller install


cloudfastservers.com

Cloud VPS Linux and Windows






Also tagged with one or more of these keywords: Tutorial

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users